我想在我的Android应用中使用Facebook Graph API。我试图看看我是否可以使用never expires的访问令牌登录Facebook,但我的代码总是返回Session is Invalid
。有人能告诉我在下面的代码中我做错了什么吗?感谢
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import com.facebook.AccessToken;
import com.facebook.android.Facebook;
public class MainActivity extends Activity {
Facebook fb;
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fb = new Facebook(getString(R.string.APP_ID));
fb.setAccessToken(getString(R.string.ACCESS_TOKEN));
//Expiry is set to 0, since the token never expires
fb.setAccessExpires(0);
if (fb.isSessionValid()) {
Toast.makeText(this, "Session is valid",
android.widget.Toast.LENGTH_LONG).show();
Log.d("TAG2", getString(R.string.ACCESS_TOKEN));
} else
Toast.makeText(this,
"Session is Invalid"+ getString(R.string.ACCESS_TOKEN),
android.widget.Toast.LENGTH_LONG).show();
Log.d("TAG3", getString(R.string.ACCESS_TOKEN));
}
}