Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook SDK with Android, get code instead of access token

I'm building an app containing a WebView that loads a website. When the user presses on the "connect with Facebook" on the website I immediately open up the "Login with Facebook" using the Facebook SDK to make the authentication step easier using the app on the user device instead of the web form.

Now, my website is using vBulletin that when login finished it is redirected to:

http://mywebsite.com/community/index.php?dofbredirect=1&code=[MY_CODE]&state=[SOME_STATE]

The state I can get from the webview which was loaded when the user pressed the "Connect with facebook" in the website, but the code is something that I can't have, I can only obtain access token.

Is there is any method of exchanging code instead of access token using the Facebook SDK?

like image 543
Shynet Avatar asked Apr 14 '15 08:04

Shynet


People also ask

How can I remove access token from Facebook?

Simply click on ones you want to revoke, and like Facebook, you will see details of that website. Click “Revoke access” at the bottom and that's it. Instead of asking you to confirm like Facebook does, Twitter turns the revoke link into an “undo revoke access” link if you suddenly change your mind.


1 Answers

The SDK request a response_type of value token. It looks like to achieve what you want, you need to manually build the login handler and request a response_type of value code. More about this here: https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/

Source: https://github.com/facebook/facebook-android-sdk/blob/b384c0655fe96db71229bfdcb981a522f3f1e675/facebook/src/com/facebook/internal/ServerProtocol.java#L59-L60

like image 87
ifaour Avatar answered Oct 15 '22 19:10

ifaour