Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle Drive invalid credentials
    primarykey
    data
    text
    <p>I am using GAE for java and trying to read files from google drive using apis. I used the standard implementation from DrEdit. I have a servlet which authenticate with my account and store the credentials using the following snippet:</p> <pre><code> protected void handleCallbackIfRequired(HttpServletRequest req, HttpServletResponse resp) throws IOException { String code = req.getParameter("code"); System.out.println("Code:" + code); if (code != null) { // retrieve new credentials with code Credential credential = credentialManager.retrieve(code); credentialManager.save(id, credential); System.out.println("access token:" + credential.getAccessToken()); System.out.println("refresh token:" + credential.getRefreshToken()); resp.sendRedirect("/"); } </code></pre> <p>}</p> <pre><code> public Credential retrieve(String code) { System.out.println("Passed code to retrieve is:" + code); try { GoogleTokenResponse response = new GoogleAuthorizationCodeTokenRequest( transport, jsonFactory, clientSecrets.getWeb().getClientId(), clientSecrets.getWeb().getClientSecret(), code, clientSecrets.getWeb().getRedirectUris().get(0)).execute(); Credential cred = buildEmpty(); cred.setRefreshToken(response.getRefreshToken()); cred.setAccessToken(response.getAccessToken()); return cred; } catch (IOException e) { new RuntimeException("An unknown problem occured while retrieving token"); } return null; } } </code></pre> <p>Code for saving the accessToken &amp; refreshToken:</p> <pre><code>protected void handleCallbackIfRequired(HttpServletRequest req, HttpServletResponse resp) throws IOException { String code = req.getParameter("code"); System.out.println("Code:" + code); if (code != null) { // retrieve new credentials with code Credential credential = credentialManager.retrieve(code); credentialManager.save(id, credential); System.out.println("access token:" + credential.getAccessToken()); System.out.println("refresh token:" + credential.getRefreshToken()); resp.sendRedirect("/"); } } </code></pre> <p>After this I am expecting the GAE to retrieve my credentials automatically each time and let me call the drive apis. However, I am seeing below message in my logs. So, I am not sure why that is happening. Please note that the authorization url i created includes offline scope.</p> <pre><code> "code" : 401, "errors" : [ { "domain" : "global", "location" : "Authorization", "locationType" : "header", "message" : "Invalid Credentials", "reason" : "authError" } ], "message" : "Invalid Credentials" } </code></pre> <p>Logs after forcing a fresh reauthentication:</p> <pre><code>2013-09-08 22:51:28.512 [s~sakshumweb-hrd/3.370083570818804963].&lt;stdout&gt;: Code:4/jYpKc6Mit2_0OTgR7dhpve0YGQCG.UoLMhsf6Fd4SEnp6UAPFm0GoUpACggI I 2013-09-08 22:51:28.512 [s~sakshumweb-hrd/3.370083570818804963].&lt;stdout&gt;: Passed code to retrieve is:4/jYpKc6Mit2_0OTgR7dhpve0YGQCG.UoLMhsf6Fd4SEnp6UAPFm0GoUpACggI I 2013-09-08 22:51:29.423 [s~sakshumweb-hrd/3.370083570818804963].&lt;stdout&gt;: access token:ya29.AHES6ZS3x8fPpq5G9YHmIvFHE098izZ0zyn7BCnZRDhYf3zdA-qNDtw I 2013-09-08 22:51:29.424 [s~sakshumweb-hrd/3.370083570818804963].&lt;stdout&gt;: refresh token:null I 2013-09-08 22:51:29.450 [s~sakshumweb-hrd/3.370083570818804963].&lt;stdout&gt;: authorization url:https://accounts.google.com/o/oauth2/auth?access_type=offline&amp;approval_prompt=auto&amp;client_id=955443778501.apps.googleusercontent.com&amp;redirect_uri=http://www.sakshum.org/GoogleOauth&amp;response_type=code&amp;scope=https://www.googleapis.com/auth/drive.readonly%20https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/userinfo.profile </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload