Hi Thira,
You are using an incorrect authorization URL. The Latitude API uses
the authorization endpoint:
https://www.google.com/latitude/apps/OAuthAuthorizeToken
See our authentication docs:
http://code.google.com/apis/latitude/v1/using_rest.html#auth
Cheers,
Ana
On Sat, May 22, 2010 at 11:41 PM, Thira <
thira...@gmail.com> wrote:
> Hi,
>
> I've encountered issues trying to get an access token from Google
> Latitude service using my Android application. I'm using the signpost
> library to perform the authentication using the following URLs:
>
> private static final String LATITUDE_REQUEST_TOKEN_URL = "https://
>
www.google.com/accounts/OAuthGetRequestTokn";
> private static final String LATITUDE_AUTHORIZE_URL = "https://
>
www.google.com/accounts/OAuthAuthorizeToken";
> private static final String LATITUDE_ACCESS_TOKEN_URL = "https://
>
www.google.com/accounts/OAuthGetAccessToken";
>
> I successfully manage to get the authentication URL, get the user to
> grant permissions (by opening a new web browser) to my application.
> However, when I try to gain an access toekn, it throws an exception
> saying "Failed to retrieve access/authentication permission./ Service
> provider responded in error: 400 (Bad Request)".
>
> I am new to using OAuth and would really appreciate if anyone can
> provide a simple example or tell me where I am going wrong (I can get
> a valid access token for other Google services using this method by
> simply changing the scope. e.g "
http://www.blogger.com/feeds").
>
> I've verified that my consumer key and secret are working properly
> using
http://googlecodesamples.com/oauth_playground.
>
> Thanks in advance!
> Thira
>
> My code looks as follows:
> mConsumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY,
> CONSUMER_SECRET);
>
> String request = LATITUDE_REQUEST_TOKEN_URL + "?scope=" +
> URLEncoder.encode("
https://www.googleapis.com/auth/latitude", "utf-8")
> mProvider = new CommonsHttpOAuthProvider (request,
> LATITUDE_ACCESS_TOKEN_URL, LATITUDE_AUTHORIZE_URL );
> String authUrl = mProvider.retrieveRequestToken(mConsumer,
> CALLBACK_URI.toString());
>
> mRequestToken = mConsumer.getToken();
> mRequestSecret = mConsumer.getTokenSecret();
> // Bring up a browser to get permission from the user as a new
> Activity
> ...
>
> // onResume method ...
> Uri uri = getIntent().getData();
> if (uri != null && CALLBACK_URI.getScheme().equals(uri.getScheme())) {
> // We got here as a result of user granting permissions
> // token
> mConsumer.setTokenWithSecret(mRequestToken, mRequestSecret );
>
> String token = uri.getQueryParameter("oauth_token");
> String verifier = uri.getQueryParameter("oauth_verifier");
>
> // I am expecting token to be the same as mRequestToken, but they
> are not if the scope is for latitude.
> // (works fine for other google services such as calendar)
>
> // Attempt to gain an access token
> // AN ERROR happens at this line
> mProvider.retrieveAccessToken(mConsumer, verifier);
> }
>
>