0

我正在尝试使用 facebook 授权我的移动应用程序,但是当 facebook 授权窗口关闭时,它不会返回到我的应用程序的 continueLoading(1) 方法.. 不明白为什么:

private void authorizeFacebook(final Loader loader) {       
    String[] permissions = new String[] {"friends_status", "user_status"};
    facebook.authorize(this, permissions , new DialogListener() {
        @Override
        public void onComplete(Bundle values) {
            Log.e("finish", "oncomplete");
            //SharedPreferences.Editor editor = mPrefs.edit();
            //editor.putString("access_token", facebook.getAccessToken());
            //editor.putLong("access_expires", facebook.getAccessExpires());
            //editor.commit();                
            loader.continueLoading(1);
        }

        @Override
        public void onFacebookError(FacebookError error) { 
            Log.i("FacebookAuthorize", error.toString());               
            app.alert("Facebook Connection Error", "Please try to re-open the application", "Ok", loader);      
        }

        @Override
        public void onError(DialogError e) { 
            Log.i("FacebookAuthorize", e.toString());               
            app.alert("Facebook Connection Error", "Please try to re-open the application", "Ok", loader);
        }

        @Override
        public void onCancel() {
            Log.i("FacebookAuthorize", "onCancel");
            app.alert("Facebook Connection Error", "Please try to re-open the application", "Ok", loader);
        }
    });

}

    @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    facebook.authorizeCallback(requestCode, resultCode, data);
}

loader的第一步:

   private void continueLoading(int step) {     
    switch(step)
    {
            //loading current user facebook profile
    case 1: progressBar.incrementProgressBy(750);               
            loadingStatus.setText("Getting user's facebook details");                               
            facebookRunner = new AsyncFacebookRunner(facebook);         
            facebookConnection = new FacebookConnection(this, 1);
            facebookRunner.request("me",facebookConnection);   
            app.setFacebook(facebook);
            app.setFacebookRunner(facebookRunner);
            break;

而不是回到我的应用程序,它只是关闭了所有东西..

4

1 回答 1

0

facebook android sdk 有两种不同的身份验证流程:

1) SSO - 如果用户在同一设备上安装了 facebook 应用程序,将使用 SSO。如果是这种情况,那么您正在使用的 facebook sdk 将对 facebook 应用程序启动一个新意图,以针对您的应用程序对用户进行身份验证。为了能够知道何时完成,您需要添加以下内容:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    facebook.authorizeCallback(requestCode, resultCode, data);
}

2) 如果设备没有安装 facebook 应用程序,那么 SDK 将打开它自己的用户身份验证对话框,在这种情况下,将使用DialogListener您传递给该authorize方法的实现。

您需要同时拥有 (DialogListeneronActivityResult) 来处理这两种情况。

于 2012-05-29T14:40:05.417 回答