0

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?

Nick
  • 3,205
  • 9
  • 57
  • 108
  • 1
    This is not possible as authorizing an app is not the same as authorizing www.facebook.com – Paul Bain Nov 13 '12 at 15:22
  • Tha page "22332332322" is not the user's home page. The user just wants to "like" this page. The idea is to bring the user to this page. After that the user just presses "like" button. – Nick Nov 13 '12 at 15:34
  • Did you manage to pass the access token to the browser with your link? please let me know if it worked, thnx :) – E_X Aug 20 '14 at 17:32

1 Answers1

3

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

Community
  • 1
  • 1
Ofir A.
  • 3,112
  • 11
  • 57
  • 83
  • This does not help. Facebook application asks to login as well as the browser. – Nick Nov 13 '12 at 15:18
  • Surely if you are already logged into the FB app it won't ask you to do this. – Paul Bain Nov 13 '12 at 15:23
  • Nevertheless, it does. Here are my steps: 1. openSession(); 2. get onSessionStateChange callback 3. start browser. On step 2 the user has been authorized. I have checked it. However, on step 3 I'm asked to authorize again. – Nick Nov 13 '12 at 15:26
  • My last comment is wrong. The reason why FB app asked me to authorize again was that I provided wrong key hash on fb dev apps page. Thank you very much, Ofir. – Nick Nov 13 '12 at 17:01