所以,这是我的登录功能:
public void facebookLogin()
{
shareAppPreferences = new AppPreferences(getApplicationContext());
facebook = ((GlobalVars)getApplicationContext()).facebook;
String access_token = shareAppPreferences.getAccessToken();
long expires = shareAppPreferences.getAccessExpires();
Log.d("MyTag","token:" +access_token);
if(access_token != null) {
facebook.setAccessToken(access_token);
}
if(expires != 0) {
facebook.setAccessExpires(expires);
}
/*
* Only call authorize if the access_token has expired.
*/
if(!facebook.isSessionValid()) {
Log.d("MyTag","In Authorize");
facebook.authorize(this, new String[] {}, new DialogListener() {
@Override
public void onComplete(Bundle values) {
// new AccessKeyTask().execute("http://37.49.226.66/allaroundme/requests.php");
shareAppPreferences.saveAccessToken(facebook.getAccessToken());
Log.d("MyTag","face token: " +facebook.getAccessToken());
shareAppPreferences.saveAccessExpires(facebook.getAccessExpires());
}
@Override
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
});
}
Intent intent = new Intent(this,MainActivity.class);
Log.d("MyTag", "starting activity");
startActivity(intent);
}
我真的不明白为什么这段代码不起作用,我在尝试使用该代码之前通过 facebook 应用程序注销了 facebook。onComplete() 似乎没有发生,并且访问令牌始终为空。但在我第一次登录后,我不必输入信息。有人能帮我一下吗?