1

我在使用 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 帐户中删除该应用程序,它会再次要求所有权限。对话框也工作正常。

4

1 回答 1

5

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

params.putString(Facebook.TOKEN, m_kFacebookClient.getAccessToken());   
于 2012-05-15T14:35:14.013 回答