我正在使用 android 中的 Facebook 应用程序。我正在运行我的应用程序一次 r 两次我的访问令牌在第三次丢失我的访问令牌后运行良好。为什么,我丢失了访问令牌?我可以做什么而不丢失访问令牌运行时。
任何人请帮助我....
编辑 1:
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
mFacebook.authorizeCallback(requestCode, resultCode, data);
}
登录按钮点击::::
mBtnFbLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("Image Button", "button Clicked");
loginToFacebook();
}
});
登录方式::::::
公共无效 loginToFacebook() {
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if (access_token != null) {
mFacebook.setAccessToken(access_token);
Log.d("FB Sessions", "" + mFacebook.isSessionValid());
Toast.makeText(getApplicationContext(), "Login SuccessFully",
Toast.LENGTH_LONG).show();
}
if (expires != 0) {
mFacebook.setAccessExpires(expires);
}
if (!mFacebook.isSessionValid()) {
mFacebook.authorize(this,
new String[] { "email", "publish_stream" },
new DialogListener() {
@Override
public void onCancel() {
// Function to handle cancel event
Log.d("FB Sessions",
"" + mFacebook.isSessionValid());
Toast.makeText(getApplicationContext(),
"Login Cancel", Toast.LENGTH_LONG).show();
}
@Override
public void onComplete(Bundle values) {
// Function to handle complete event
// Edit Preferences and update facebook acess_token
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("access_token",
mFacebook.getAccessToken());
editor.putLong("access_expires",
mFacebook.getAccessExpires());
editor.commit();
Log.d("FB Sessions",
"" + mFacebook.isSessionValid());
Toast.makeText(getApplicationContext(),
"Login SuccessFully", Toast.LENGTH_LONG)
.show();
}
@Override
public void onError(DialogError error) {
// Function to handle error
}
@Override
public void onFacebookError(FacebookError fberror) {
// Function to handle Facebook errors
}
});
}
}