Ofir A.
Ofir A.

Reputation: 3162

How to stay connected to facebook in an Android application

I am working on an application where I need to integrate the social functionality of Facebook.

In my application there is a button that connects the user to his Facebook profile. When the user press this button I'm only open a webview with the Facebook site, with the user Facebook page. Now lets say that I know his email and password and I want to connect him automatically, that he not have to enter his email and password every time. I tried to solve it throw my next question, but as you can see with no success.

I tried also persisting cookies with CookieSyncManager, CookieManager and manually handling.

I think I can solve it by changing the url that I sends to the webView, but I don't know which url. (tried http://www.facebook.com/connect/connect_to_external_page_widget_loggedin.php and http://www.facebook.com/plugins/login.php and then concatenate the url of the user Facebook page, for example http://www.facebook.com/UserProfile)

I really appreciate any help!

Thanks.

Upvotes: 5

Views: 2167

Answers (3)

Nitzan Tomer
Nitzan Tomer

Reputation: 164457

There's a way to use the SDK authentication instead of the SSO as discussed here: How to disable Facebook single sign on for android - Facebook-android-sdk.
But I think that it just results in a bad user experience since the user will need to enter his email/password which is not a fun task to do with most mobile devices.

If the user has the facebook application (katana) installed (which means the use of SSO), then you should be able to just open it with the user profile by using an intent.
I've never done it before, but from these two threads:
launch facebook app from other app
and
Open a facebook page from android app
it looks like you can do something like:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.facebook.katana", "com.facebook.katana.ProfileTabHostActivity");
this.startActivity(intent);

Upvotes: 2

Sherif elKhatib
Sherif elKhatib

Reputation: 45942

You can not manually log in the user to facebook. That is the whole point of oAuth, the process should be transparent to your app and when the user is done with authentication your app will only get an AccessToken.

From that point on, an AccessToken can stay alive with you almost for ever.

It will be invalid when :

  1. Session expires

    This can be solved by adding a call to your onResume() assuming you are using the Facebook Android SDK for authentication/integration of facebook. When this call is successful, your token will be valid for 60 days.

    public void onResume() {    
        super.onResume();
        facebook.extendAccessTokenIfNeeded(this, null);
    }
    
  2. User changes his password

  3. User de-authorizes your app

  4. User logs out of Facebook

    You can do nothing about these three cases! Your token will be invalidated and you will have to ask the user to re-authenticate using the normal flow.

Follow this tutorial to integrate Facebook inside your Android app

Upvotes: 4

Akilan
Akilan

Reputation: 1717

For connecting to facebook, you have learn Oauth first. Oauth is a one time verification to access facebook details. Password does not requires every time. Go through this documentation.

And this document also useful for you.

Upvotes: 0

Related Questions