Reputation: 23352
I am trying Google OAuth.I am developing web application running on IBM webSphere server. Application's framework is SpringMVC.
I am trying to get userinfo.profile. I have successfully get Access Token and could not find a way to use this token and get user information.
I was redirecting browser to this URL https://www.googleapis.com/oauth2/v2/userinfo?access_token="+access.getAccessToken();
but getting error
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
Am I using this access token fine or should I send request in some other form?
I am sending request in this way:
GenericUrl shortenEndpoint = new GenericUrl("https://www.googleapis.com/oauth2/v2/userinfo");
HttpRequest request1 = rf.buildGetRequest(shortenEndpoint);
GoogleHeaders headers = new GoogleHeaders();
headers.setContentType("application/json; charset=UTF-8");
headers.setAuthorization("OAuth " + accessToken);
request1.setHeaders(headers);
HttpResponse shortUrl = request1.execute();
After giving my Access Token in this URL in browser
https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=******
I got
{
"issued_to": "*****************",
"audience": "*****************",
"scope": "https://www.googleapis.com/auth/urlshortener",
"expires_in": 3515,
"access_type": "online"
}
Upvotes: 0
Views: 9254
Reputation: 628
It seems that your authorization header is incorrect.
Try with : headers.setAuthorization("OAuth " + accessToken);
Upvotes: 1
Reputation: 3344
Looking at the tokeninfo response, there is a mismatch between the scope for which the token was issued and the API you are trying to access. You seem to have an access token for https://www.googleapis.com/auth/urlshortener scope. If you want to user the userinfo API, you should obtain a token for the https://www.googleapis.com/auth/userinfo.profile and https://www.googleapis.com/auth/userinfo.email scopes.
Upvotes: 6