Getting Google Play Games player ID on server

南笙酒味 提交于 2019-12-08 11:29:25

问题


The post Play Games Permissions are changing in 2016 explains how to get the Play Games player ID on a server. I can successfully get the access token on the server, but I can't get this step to work:

  1. Once you have the access token, call www.googleapis.com/games/v1/applications/yourAppId/verify/ using that access token. Pass the auth token in a header as follows: “Authorization: OAuth ” The response value will contain the player ID for the user.

I'm trying to do that in Google App Engine using:

accessToken = ...;   //-- I can always get this successfully
URL url = new URL(String.format("https://www.googleapis.com/games/v1/applications/%s/verify/",myAppId));    
HTTPRequest request = new HTTPRequest(url, HTTPMethod.GET);
HTTPHeader httpHeader = new HTTPHeader("Authorization: OAuth",accessToken);
request.addHeader(httpHeader);
HTTPResponse httpResponse = urlFetchService.fetch(request);

The response always return code 401. How can I debug?


回答1:


An identical issue (sort of) indicates that you'll have to set the header differently (not using HttpHeader).

httppost.setHeader("Authorization", "Bearer "+accessToken);

Hopefully this can fix your issue.




回答2:


The problem was with the header, it should be added like this:

HTTPHeader httpHeader = new HTTPHeader("Authorization","OAuth " + accessToken);


来源:https://stackoverflow.com/questions/36510996/getting-google-play-games-player-id-on-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!