SmartDroidDeveloper / google-api-java-client

Automatically exported from code.google.com/p/google-api-java-client
0 stars 0 forks source link

How I can reuse stored tokens to do future queries ? #41

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Which API and version (e.g. Google Calendar Data API version 2)?
  google-api-java-client.1.1.0-alpha

What format (e.g. JSON, Atom)?
  JSON and Atom

What Authentation (e.g. OAuth, OAuth 2, Android, ClientLogin)?
  We need an example to OAuth 2

Java environment (e.g. Java 6, Android 2.2, App Engine 1.3.7)?
  Java 6

External references, such as API reference guide?
  We are using the picasa API

Please provide any additional information below.

1. We are runing the picasa-atom-oauth-sample and it works perfect.
2. The example have a "private static OAuthCredentialsResponse credentials;"
3. Execute the next code to obtain the access tokens:
    GoogleOAuthGetAccessToken accessToken = new GoogleOAuthGetAccessToken();
    accessToken.temporaryToken = tempToken;
    accessToken.signer = signer;
    accessToken.consumerKey = "www.mydomain.com" /*"anonymous"*/;
    accessToken.verifier = verifier;
    credentials = accessToken.execute();
    signer.tokenSharedSecret = credentials.tokenSecret;

4. We are storing the credentials.token and credentials.tokenSecret for future 
reuse, but when we try to reuse the tokens in other programs it send me a "403 
Forbidden":
Exception in thread "main" com.google.api.client.http.HttpResponseException: 
403 Forbidden
    at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:219)
    at com.google.api.client.sample.picasa.model.Feed.executeGet(Feed.java:51)
    at com.google.api.client.sample.picasa.model.UserFeed.executeGet(UserFeed.java:37)
    at com.google.api.client.sample.picasa.AuthTest1.showAlbums(AuthTest1.java:54)
    at com.google.api.client.sample.picasa.AuthTest1.<init>(AuthTest1.java:46)
    at com.google.api.client.sample.picasa.AuthTest1.main(AuthTest1.java:94)

5.  We have a registered application in 
https://www.google.com/accounts/ManageDomain, and we are using the parameters:
    OAuth Consumer Key:    www.mydomani.com
    OAuth Consumer Secret: XXXXXXXXXXXXXXXXXXXXXXXX

Can you give us a correct example of how to get access and how to reuse stored 
tokens? 

Original issue reported on code.google.com by carlosec...@gmail.com on 11 Oct 2010 at 11:23

Attachments:

GoogleCodeExporter commented 9 years ago
According to Google's OAuth documentation, for installed applications you must 
use anonymous/anonymous for the consumer key and secret.  Specifying consumer 
key and consumer only works for the web application running on the domain that 
matches the consumer key.  In your case, that would be "mydomain.com".

That said, please check the content of the error message by adding something 
like this code:

try {
  ReuseAuthTest1 authTest1 = new ReuseAuthTest1();
} catch (HttpResponseException e) {
  System.out.println(e.response.parseAsString());
  throw e;
}

If the error message does not clearly explain what the problem is, please file 
a bug on http://code.google.com/p/gdata-issues/

Original comment by yan...@google.com on 11 Oct 2010 at 12:30

GoogleCodeExporter commented 9 years ago
Thanks yan...@google.com

IT works perfectly now, and the tip of 
"System.out.println(e.response.parseAsString());" shows the error message much 
more clear.

Thanks again..!!

Original comment by carlosec...@gmail.com on 12 Oct 2010 at 1:07

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 21 Oct 2010 at 3:11