How to get the access token in google app engine endpoints for User object?
<p>I am able to get the User Google information such as email and nick name . But I want to retrieve the user profile image from the scope <code>https://www.googleapis.com/auth/userinfo.profile</code></p>

<p>To access that I need to call this<br>
<code>https://www.googleapis.com/oauth2/v1/userinfo?alt=json&amp;access_token=XXX</code></p>

<p>This will return back the Json data containing the link to profile picture.
Sample response for above request with access_token </p>

<pre><code>{
  "id": "123",
  "name": "Admin User",
  "given_name": "Admin",
  "family_name": "User",
  "link": "https://plus.google.com/XYZ",
  "picture": "https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/XYX/4252rscbv5M/photo.jpg",
  "locale": "en"
}
</code></pre>

<p>How do I get the access token in Java? </p>

<p>My code is pasted below:</p>

<pre><code>package com.example.myapplication.backend;

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiNamespace;
import com.google.appengine.api.oauth.OAuthRequestException;
import com.google.appengine.api.users.User;

import java.io.IOException;

/** An endpoint class we are exposing */
@Api(
  name = "myApi",
  version = "v1",

        scopes = { Constants.EMAIL_SCOPE2 },
        clientIds = { Constants.WEB_CLIENT_ID, Constants.ANDROID_CLIENT_ID,
                Constants.API_EXPLORER_CLIENT_ID},
        audiences = {Constants.ANDROID_AUDIENCE},


  namespace = @ApiNamespace(
    ownerDomain = "backend.myapplication.Ajay.example.com",
    ownerName = "backend.myapplication.Ajay.example.com",
    packagePath=""
  )
)
public class MyEndpoint {

    /** A simple endpoint method that takes a name and says Hi back */
    @ApiMethod(name = "sayHi")
    public MyBean sayHi( User user) throws OAuthRequestException, IOException
     {
        MyBean response = new MyBean();
         response.setData(user.getEmail() + "  nick name-&gt;" + user.getNickname() + "user id " + user.getUserId() + "--&gt;" +
                 user.toString() + "getAuthDomain---&gt;" + user.getAuthDomain().toString()+" token");
        return response;
    }


}
</code></pre>