Android Facebook实施SSO

时间:2011-11-01 18:08:51

标签: android facebook single-sign-on

我想在我的Android应用程序中实现Facebook Connect。我看过像foursquare这样的应用程序,当你点击Facebook登录时,它会跳转到安装在设备中的Facebook应用程序并请求权限,一旦被授予,就会返回应用程序并登录。

我尝试从以下页面实现代码 https://developers.facebook.com/docs/mobile/android/sso/

但是当我点击登录时,会弹出一个Web视图对话框,并输入用户名和密码。

任何人都可以参考一下关于Facebook Android SDK SSO的一些教程

public class SplashActivity extends Activity {

    private Button loginButton, signupButton, FacebookButton;

    public static final String APP_ID = "11232201730";
    Facebook facebook = new Facebook("APP_ID");

    String[] permissions = { "user_about_me", "email", "user_birthday",
            "user_location", "publish_stream" };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        FacebookButton = (Button) findViewById(R.id.FacebookLogin);
        FacebookButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {

                facebook.authorize(this, new Facebook.DialogListener() {

                    public void onFacebookError(FacebookError e) {
                        // TODO Auto-generated method stub

                    }

                    public void onError(DialogError e) {
                        // TODO Auto-generated method stub

                    }

                    public void onComplete(Bundle values) {
                        // TODO Auto-generated method stub

                    }

                    public void onCancel() {
                        // TODO Auto-generated method stub

                    }
                });


            }
        });

    }
}

错误

Facebook类型中的方法授权(Activity,Facebook.DialogListener)不适用于参数(new View.OnClickListener(){},new Facebook.DialogListener(){})

1 个答案:

答案 0 :(得分:3)

facebook.authorize(this, new Facebook.DialogListener()

应该是

facebook.authorize(SpashActivity.this, new Facebook.DialogListener()