API Services Games , error "message": "Login Required", with token correct in your page REST API

209 views
Skip to first unread message

Arturo Dormilon

unread,
Apr 22, 2020, 8:12:16 AM4/22/20
to Google App Engine

I've been trying to connect passing the token correctly and I always get the same error:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

My code is:

function start() {
    alert("paso");
        gapi.client.init({
            apiKey: 'AIza***********************',
            clientId: '415249084355-01r************************',
        //  discoveryDocs: 'https://www.googleapis.com/games/v1/',
            scope: 'https://www.googleapis.com/auth/games',
          })
        //  gapi.client.setToken(idtok);
          // Loading is finished, so start the app
          .then(function() {

            gapi.client.load('games', 'v1', function(response) {   
                var request = gapi.client.games.leaderboards.list(  
                             {maxResults: 5}                    );    
                  request.execute(function(response) {       
                    console.log("esta es la respuesta list" + response);                                 }); 
                                                                      });      


            gapi.client.load('games', 'v1', function(response) {   
                alert("paso2");
                userIdToken = firebase.auth().currentUser.getIdToken();
            gapi.client.setToken(userIdToken);
            gapi.client.setApiKey('AIzaSyDsWd6D**************************');
        // 3. Initialize and make the API request.
                    gapi.client.request({
                        path: 'https://www.googleapis.com/games/v1/achievements',
                        methods: 'https://www.googleapis.com/games/v1/achievements',
                        params: { language: 'es-ES', maxResults: 150, pageToken: userIdToken },
                        callback: function (response) {
                            console.log("esta es la respuesta logros" + response);
                                }
                    });
                });
          });   
};

If I access from my own Google API testing page, from where the loi api is approved, it doesn't work either

Thanks

Aref Amiri (Cloud Platform Support)

unread,
Apr 22, 2020, 3:17:35 PM4/22/20
to Google App Engine
Since the issue is related to Play Game Services, I'd suggest to post your question Stackoverflow, as there are dedicated members ready to assist you with the issue. Please note that this discussion group is oriented more towards general opinions, trends, and issues of general nature touching App Engine.
Reply all
Reply to author
Forward
0 new messages