问题
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:
- 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