Nick
Nick

Reputation: 3435

android-facebook-sdk open facebook page

I use facebook-android-sdk-3.0.1.b to integrate my Android app with Facebook. After user has logged in (explicitly or implicitly - does not matter), the callback is called:

@Override
protected void onSessionStateChange(SessionState state, Exception exception) {
    if (state.isOpened()) {         
        final String urlString = "http://www.facebook.com/22332332322";
        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(urlString)));
    }
}

As you can see, I launch a broswer passing it some facebook page. My goal is to allow user to "like" this page. However, as user presses "like" button on this page, he is asked to authorize. That's not good because he has already authorized.

I am interested is it possible to extract authorization information (access token or whatever) from facebook-android-sdk and pass this information to the browser?

Update

I have found that it is possible to obtain access token for a session:

final String accessToken = getAccessToken();

But how can I pass it to the browser to make the user logged in?

Upvotes: 0

Views: 2171

Answers (1)

Ofir A.
Ofir A.

Reputation: 3162

We had this problem also. In our case we assume that if the user has a Facebook account he also have the Facebook app on his device. So, in that case when the user push the "Follow Us" button we just open the Facebook app with our page, the user only needs to press the "Like" button and that's it.

In case the user don't have the application on his device, we open a browser with our Facebook page.

You can do it like this:

try{

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/22332332322)); 
startActivity(intent);

}catch(Exception e){

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/22332332322")));
}

Another possibility is to use Single Sign On from the Facebook API, this is more user friendly method. The user can see what exactly you want and can authorized or not.

As you said, you can get the access token, but I don't think you can pass it to the browser. I tried it half a year ago and didn't find any answer to that.

You can check my questions, It might help you:

link1

link2

link3

link4

Upvotes: 3

Related Questions