我有以下连接 facebook 的活动
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_facebook);
mFacebook = SavvyActivityDelegate.get().getFacebook(this);
if (mFacebook.isSessionValid()) {
// TODO GET FB ACCESS TOKEN
} else {
mFacebook.authorize(this, FacebookConstants.PERMISSIONS, new AppFacebookDialogListener(FacebookActivity.this,mFacebook));
}
public void onActivityResult(int request, int result, Intent data) {
super.onActivityResult(request, result, data);
mFacebook.authorizeCallback(request, result, data);
}
这是使用的对话侦听器
public class AppFacebookDialogListener implements Facebook.DialogListener {
private final Activity activity;
private final Facebook facebook;
public SavvyFacebookDialogListener(Activity activity, Facebook facebook) {
this.activity = activity;
this.facebook = facebook;
Log.d(LogTag.app, "Facebook constructor"); // activity.finish(); }
@Override public void onComplete(Bundle values) {
Log.d(LogTag.app, "Facebook authorization complete!");
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(activity).edit();
editor.putLong("fb_access_expires", facebook.getAccessExpires());
editor.putString("fb_access_token", facebook.getAccessToken());
editor.commit(); }
@Override public void onFacebookError(FacebookError e) {
Log.e(LogTag.app, e.getErrorType() + ": " + e.getMessage() + " (code: " + e.getErrorCode() + ")", e); }
@Override public void onError(DialogError e) {
Log.e(LogTag.app, e.getMessage(), e); }
@Override public void onCancel() {
Log.d(LogTag.app, "Facebook authorization was cancelled"); } }
活动开始时的日志声明
06-06 15:09:19.314: I/ActivityManager(404): 从 pid 17947 开始 u0 {cmp=com.biggu.shopsavvy/.FacebookActivity} 06-06 15:09:19.392: D/ShopSavvy(17947): Facebook构造函数 06-06 15:09:19.400: I/ActivityManager(404): START u0 {cmp=com.facebook.katana/.ProxyAuth (has extras)} from pid 17947 06-06 15:09:19.415: I/ActivityManager (404):从 pid 15214 开始 u0 {cmp=com.facebook.katana/.ProxyAuthDialog(有附加功能)}
因此,根据日志,对话构造函数被调用,但没有任何回调方法被调用。
如果未安装 facebook 应用程序,则代码工作正常,我完成了回调授权,但代码在具有 facebook 应用程序且用户已登录的设备上表现异常。提前致谢 。