简体   繁体   中英

Login on facebook from an android app

In my app I have a 2 edittext (for email and password) and a simple button "Facebook connect" and when I choose this button I want to go to sign in page of facebook. Is it possible what I am trying to do or I must login on facebook from facebook login page? If it's possible,how should I do this?

you have to download api from this link https://github.com/facebook/facebook-android-sdk/

and after that take code for facebook api of java from this link

http://developers.facebook.com/docs/guides/mobile/

try this:

public void onClick(View v) {

        Intent i = getOpenFacebookIntent(this);
        startActivity(i);

    }


public static Intent getOpenFacebookIntent(Context context) {

    try {
        context.getPackageManager().getPackageInfo(
                "com.facebook.facebook", 0);
        return new Intent(Intent.ACTION_VIEW,
                Uri.parse("fb://profile/20531316728"));
    } catch (Exception e) {
        return new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://www.facebook.com/facebook"));
    }
}

when you click on your button (or for example a facebook icon as an image button)

Your android browser will pops up and then you can login to facebook.

In the code above I use the page facebook.com/facebook to be browsed but you can use any other page you like but first you need to exctract the page's id from here:

graph.facebook.com/yourpage

(for example in code above the id is 20531316728 where you can find it in: graph.facebook.com/facebook)

did you have a look at the official Facebook Android SDK? android-sdk

You have to follow https://github.com/facebook/facebook-android-sdk/

Here the idea is avoid login in your app if you have already logged into official facebook app. Otherwise it will pop up an custom dialog.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM