OAuth令牌无效:错误2500

时间:2012-05-15 12:28:24

标签: android facebook

使用Facebook OAuth方法时,我遇到了一个反复出现的问题。尽管尝试我自己的实现,一切都应该是合规的,对话框工作正常,但当我尝试做请求时,我一直收到错误2500。我在oncreate中调用的登录代码如下:

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 }
    }

和我在onCreate中完成的发布方法是

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 }

我尝试获取令牌信息,这是正确的:

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}}

编辑:如果我添加“offline_access”权限,则令牌变得错误。

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

至于行为,它在我第一次登录后从未要求我登录。如果我从手机上卸载它,我需要再次登录,如果我从我的FB帐户中删除了应用程序,它会再次请求所有权限。对话也很好。

1 个答案:

答案 0 :(得分:5)

看起来你根本就没有设置访问令牌。请试试这个:

params.putString(Facebook.TOKEN, m_kFacebookClient.getAccessToken());