开发者

Android facebook api authorization

Im trying to use official facebook api for android and I found a strange thing in the auth process. The code was cut from the official example.

@Override
public void onCreate(Bundle savedInstanceState) { 
   mFacebook = new Facebook(APP_ID); 
}

@Override
protected void onActivityResult(int requestCode, int resultCode,
                                Intent data) {
    mFacebook.authorizeCallback(requestC开发者_运维百科ode, resultCode, data);
}

 private final class ButtonOnClickListener implements OnClickListener {

    public void onClick(View arg0) {
       mFacebook.authorize(mActivity, mPermissions, new LoginDialogListener());
    }
} 


private class SessionListener implements AuthListener, LogoutListener {
   public void onAuthSucceed() {
       setImageResource(R.drawable.logout_button);
       SessionStore.save(mFb, getContext());
   }
} 

So in the onClick you give a reference to your activity, because you'll get the result of the login process in the onActivityResult.

The strange thing that if your activity is killed while youre on the login screen your facebook object will be reinstantiated in onCreate and after the authorizeCallback call none of your SessionListener's method is getting invoked.

The problem is that I have an upload method which would be called in onAuthSucceed().

Does anyone have a solution for this?


So I was examining the original Facebook source and found the thing:

public void authorizeCallback(int requestCode, int resultCode, Intent data) {
   if (requestCode == mAuthActivityCode) {
        // when you have a new object the mAuthActivityCode is 0

   //...
    mAuthDialogListener.onFacebookError(
                            new FacebookError(error));
    // even if you start auth with requestCode 0, your mAuthDialogLister will be null

}

I extended the Facebook class so that I can pass the required things.

You can find the source here: https://github.com/facebook/facebook-android-sdk/blob/master/facebook/src/com/facebook/android/Facebook.java

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜