I am having a recurring problem while using Facebook OAuth methods. Despite trying my own implementation everything is supposed to be compliant and dialogs are working fine, but I keep getting error 2500 when I tried to do requests. My login code, called in oncreate, is as follows:
mPrefs = m_kActivity.getPreferences(m_kActivity.MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if(access_token != null) {
m_kFacebookClient.setAccessToken(access_token);
}
if(expires != 0) {
m_kFacebookClient.setAccessExpires(expires);
}
/*
* Only call authorize if the access_token has expired.
*/
if(!m_kFacebookClient.isSessionValid()) {
m_kFacebookClient.authorize(m_kActivity, new String[] {
"publish_stream", "read_stream" },
new Facebook.DialogListener() { // OVERLOADS }
}
and my publish method, done in onCreate too, is
byte[] data = null;
String dataPath = "/mnt/sdcard/DCIM/100MEDIA/VIDEO0001.3gp";
String dataMsg = "TestStuff";
String dataName = "VIDEO0001.3gp";
Bundle param;
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(m_kFacebookClient);
InputStream is = null;
is = new FileInputStream(dataPath);
data = readBytes(is);
param = new Bundle();
param.putString("message", dataMsg);
param.putByteArray("video", data);
param.putString("filename", dataName);
mAsyncRunner.request("me", param, "POST",
new AsyncFacebookRunner.RequestListener() { // OVERLOAD }
I tried getting the token info and it is correct:
05-15 14:53:17.149: D/myapp(7964): access token = AAACmjJqKCmMBAFRMjn49t7DvXEPlRyKnbdghdthdth31654651oGGJnBpSxEiLb5R3ZAxEEoI0x4JAfCvnQWIyK08cmzUGqX1I2IeeyV
05-15 14:53:17.149: D/myapp(7964): expiration = 1337090401151
05-15 14:53:17.169: D/myapp(7964): expiration datetime = Tue May 15 16:00:01 CEST 2012
05-15 14:53:17.169: D/myapp(7964): is session valid? true
05-15 14:54:48.849: D/myapp(7964): {"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}
EDIT: If I add "offline_access" permission the token becomes erroneous.
05-15 15:24:06.639: D/myapp(8180): expiration = 0
05-15 15:24:06.669: D/myapp(8180): expiration datetime = Thu Jan 01 01:00:00 CET 1970
05-15 15:24:06.679: D/myapp(8180): is session valid? true
As for the behaviour, it never asks me to log in after I logged the first time. If I uninstall it from the phone I need to log in again, and if I delete the App from my FB account it asks for all permissions again. Dialogs are working fine too.