2012-04-27 94 views
1

我想爲我的應用程序創建一個Facebook登錄按鈕。Android的Facebook登錄與OnClickListener

我的問題是,我想打電話給「授權」與OnClickListener,但月食標誌着「授權」部分爲錯誤。它建議用authorizeCallback替換它,但它不是解決方案。

看來我只是想念一些東西,但不知道是什麼。請任何想法嗎?

這是錯誤發生時(facebook.authorize):

LoginButton.setOnClickListener(new OnClickListener() 
{ 
     public void onClick(View v) 
     { 
     facebook.authorize(this, new String[] { "email", "user_birthday" }, new FacebookLoginDialogListener());  
      }}); 
    } 

休息代碼:

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

public class FacebookLoginDialogListener implements DialogListener 
    { 
     public void onComplete(Bundle values) { 
      SharedPreferences.Editor editor = mPrefs.edit(); 
      editor.putString("access_token", facebook.getAccessToken()); 
      editor.putLong("access_expires", facebook.getAccessExpires()); 
      editor.commit(); 
      requestUserData(); 
     } 

     public void onFacebookError(FacebookError error) {} 

     public void onError(DialogError e) {} 

     public void onCancel() {} 

    } 

回答

2

做到這一點的方法:

facebook.authorize(YourActivity.this, new String[] { "email", "user_birthday" }, new FacebookLoginDialogListener()); 

你是通過OnClickListenerthis引用必須將方法通過Activity'sContext