Domanda

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!

È stato utile?

Soluzione

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.

Altri suggerimenti

You've got it all wrong. OAuth 2 Protocol never returns a request token like OAuth 1.

Oauth 1 does an HTTP POST request and returns an unauthorized request token. Then, you will have to authorize your unauthorized token to receive an authorized token (That's 2 HTTP call).

Oauth 2, on the other hand, doesn't have a request token flow, you will need to do an HTTP GET for an authorization token (1 HTTP call only). Hence why Scribe says that you need to call getAuthorizedUrl.

See this Facebook Example, to see how to retrieve an authorized token using OAuth 2.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top