1

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.

MLProgrammer-CiM
  • 17,231
  • 5
  • 42
  • 75
  • check your token here: https://developers.facebook.com/tools/debug - it is invalid. Probably a character is cut off? – avs099 May 15 '12 at 13:24
  • Issued: 1337088246 (4 minutes ago) Expires: Never Valid: True Origin: Mobile Web Faceweb Scopes: create_note offline_access photo_upload publish_actions publish_stream read_stream share_item status_update video_upload – MLProgrammer-CiM May 15 '12 at 13:28
  • the token from your post does not work. Do you have another one? Also - is it app token or user token? – avs099 May 15 '12 at 13:33
  • I manually edited the token before posting so nobody else could use it :) The debug gives me both appid and userid but I don't know if it's app or user token. I retrieve it using myFacebook.getAccessToken() – MLProgrammer-CiM May 15 '12 at 13:38
  • expire: Never suggests to me that this is app token. Can you try mAsyncRunner.request("", .. instead of mAsyncRunner.request("me", ? – avs099 May 15 '12 at 14:10
  • Different error, thats a good sign: {"error":{"message":"An access token is required to request this resource.","type":"OAuthException","code":104}} – MLProgrammer-CiM May 15 '12 at 14:19
  • oh - you are not passing token at all :) you need to correct your code - probably put it into params Bundle – avs099 May 15 '12 at 14:21
  • Can you give me a snippet of the changes, please? – MLProgrammer-CiM May 15 '12 at 14:23

1 Answers1

5

looks like you are not setting access token at all. Try this please:

params.putString(Facebook.TOKEN, m_kFacebookClient.getAccessToken());   
avs099
  • 10,937
  • 6
  • 60
  • 110
  • 100: "Can only call this method on valid test users for your app". I do not have access to app configuration :( – MLProgrammer-CiM May 15 '12 at 14:51
  • i guess your app is still in test mode then. I would suggest you create completely new app - which you will have full control on, and debug your program against it - and when all is done and working, you will only have to replace APP_ID in your app, and that should be it. But you have to have the control of the app during development. It will make things much easier. – avs099 May 15 '12 at 14:55
  • It *should't* be because it's an already released app (hence why I'm editing my tokens) and users can join and whatnot. – MLProgrammer-CiM May 15 '12 at 15:10
  • Amnyway, why can I create new posts using dialogs but not using requests? – MLProgrammer-CiM May 15 '12 at 15:35
  • Apparently I needed param.putString("name", videoName); also. – MLProgrammer-CiM May 16 '12 at 15:20