Android Facebook.authorize不要调用oncomplete方法 [英] Android Facebook.authorize don't call oncomplete method
问题描述
在Facebook.authorize完成工作后,从来不叫
如果我用Facebook.FORCE_DIALOG_AUTH使用facebook.authorize,在这种情况下,调用onComplete方法,我可以保存access_token。
我附上一段我的代码。
任何人都可以帮我解决这个问题吗?
if(!facebook.isSessionValid()){
facebook.authorize(Login.this,new String [] {publish_stream,read_stream,offline_access},//Facebook.FORCE_DIALOG_AUTH,
new DialogListener(){
@Override
public void onComplete(Bundle values){
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString(access_token,facebook.getAccessToken() );
editor.putLong(access_expires,facebook.getAccessExpires());
editor.commit();
}
@Override
public void onFacebookError(FacebookError error){Log.e(FB:,Facebook Error);}
@Override
public void onError(DialogError e){Log.e FB,错误);}
@Override
public void onCancel(){}
});
}
感谢
Simo
确保您实现了 onActivityResult()
,正如官方文档:
@Override
public void onActivityResult(int requestCode,int resultCode,Intent data){
super.onActivityResult(requestCode,resultCode,data);
facebook.authorizeCallback(requestCode,resultCode,data);
}
I'm trying to integrate facebook login on my android app. I found a lot of examples on internet, but now I have the following problem and I can't find a solution.
After facebook.authorize finish work, the oncomplete method is never called. If I use the facebook.authorize with Facebook.FORCE_DIALOG_AUTH, in this case the oncomplete method is called and I can save the access_token. I attach a snipped of my code. Can anyone help me to solve this problem?
if(!facebook.isSessionValid()) {
facebook.authorize(Login.this, new String[] {"publish_stream","read_stream", "offline_access"}, //Facebook.FORCE_DIALOG_AUTH,
new DialogListener() {
@Override
public void onComplete(Bundle values) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token", facebook.getAccessToken());
editor.putLong("access_expires", facebook.getAccessExpires());
editor.commit();
}
@Override
public void onFacebookError(FacebookError error) {Log.e("FB:","Facebook Error" );}
@Override
public void onError(DialogError e) {Log.e("FB:","Error" );}
@Override
public void onCancel() {}
});
}
Thanks Simo
Make sure that you implemented onActivityResult()
properly as stated in the official documentation:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
这篇关于Android Facebook.authorize不要调用oncomplete方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!