Oauth problems with Scribe

Javier Manzano picture Javier Manzano · Dec 20, 2011 · Viewed 9.6k times · Source

I'm using scribe for making an app that has oauth support. I didn't found problems With Twitter, but when using facebook I have problems...

This is the code that works on twitter oauth

OAuthService s = /* ... Facebook oauth init ... */
final Token requestToken = s.getRequestToken();
final String authURL = s.getAuthorizationUrl(requestToken);

It gives me an error at the second line:

12-20 10:01:31.475: E/AndroidRuntime(5405): java.lang.UnsupportedOperationException: Unsupported operation, please use 'getAuthorizationUrl' and redirect your users there
12-20 10:01:31.475: E/AndroidRuntime(5405):     at org.scribe.oauth.OAuth20ServiceImpl.getRequestToken(OAuth20ServiceImpl.java:45)

I know that it says that I might use getAuthorizationUrl... But I have to pass a requestToken...

Could you please help me?

It would be helpful any example with Scribe and Facebook

Thanks!

PS: Same problem with Windows Live ! =(

EDIT:

I have been looking at the source code of the Scribe library and I found something

https://github.com/fernandezpablo85/scribe-java/blob/master/src/main/java/org/scribe/oauth/OAuth20ServiceImpl.java

Here we can see that I can call the getAuthorizationUrl(...) with null parameter because it doesn't use it.... But I think the prioblem now is that the config isn't filled...

here is how I initialize facebook service:

new ServiceBuilder()
    .provider(FacebookApi.class)
    .apiKey(....)
    .apiSecret(....)
    .scope("email,offline_access")
    .callback("oauth://facebook")
    .build();

Is this correct?

Thanks!

Answer

Umesh Awasthi picture Umesh Awasthi · Dec 20, 2011
private static final Token EMPTY_TOKEN = null;

OAuthService service = new ServiceBuilder()
                           .provider(FacebookApi.class)
                            .apiKey(apiKey)
                            .apiSecret(apiSecret)
                             .callback("http://www.example.com/oauth_callback/")
                              .build();
 String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);

All you now need to redirect user to this URL and let him verify them self to get code from facebok.

There are a good amount of example with very good documentation for almost all major Oath system

here is for Facebook

FacebookExample

For all major providers Scribe Example Directory

Edit

After looking at the discussion my suggestion is to get a full understanding about Oauth1 and Oauth2.