开发者

Android - OAuthException - I keep getting: "An active access token must be used to query information about the current user"

开发者 https://www.devze.com 2023-02-10 09:31 出处:网络
I\'ve used this exact code and others that work to a certain degree, but I keep getting the following error:

I've used this exact code and others that work to a certain degree, but I keep getting the following error:

{"error":{"type":"OAuthException","message":"An active access token must be used to query information about the current user."}}

Here is the code: I've used the access_token I get back and validated it against plugging it into my browser and it works great. But this code seems to either not be using the access token I get back, or I'm not setting it. I've even tried the FB.setAccessToken() method as well as params.putString("access_token", MY_ACCESS_TOKEN).

I'm wondering, since I did not need to change the access token for the website url to work, I would not think that I don't need to do anything special to the access_token like ecoding it like in a url?

Thanks for your help. I've scoured the net for answers for hours and there seems to not be any.

Bundle params = new Bundle();

params.putString("message", "Test");
params.putString("name", "American Virgin");
params.putString("link", "http://bit开发者_StackOverflow.ly/12345");
params.putString("description", "A Freshman College Girl on a scholarship from an ...");
params.putString("picture", "http://xxx/MOV1026.jpg");

mAsyncRunner.request("me/feed", params, "POST", new TestRequestListener());


Did you try to include the below code?

@Override  
protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
        mFacebook.authorizeCallback(requestCode, resultCode, data);  
}  

According to the documentation, this must be included or the authentication will not function properly, which in turn could cause the error you're encountering. I had the same problem but then realized I was missing this.


now it works fine. i have just put code in comment.

 public void authorize(Activity activity, String[] permissions,
        int activityCode, final DialogListener listener) {

    boolean singleSignOnStarted = false;

    mAuthDialogListener = listener;

    // Prefer single sign-on, where available.
    //if (activityCode >= 0) {
    //      singleSignOnStarted = startSingleSignOn(activity, mAppId,
    //             permissions, activityCode);
    //  }
    // Otherwise fall back to traditional dialog.
    if (!singleSignOnStarted) {
        startDialogAuth(activity, permissions);
    }
} 


The access token you receive needs to be URL Decoded.
I used URLDecoder.decode() with MultiPartEntity(HttpMultipartMode.STRICT);


I just encountered this error message from a different cause. The AsyncFacebookRunner seems to pull values from the Facebook object at the time it is passed in, rather than holding a reference to it. Therefore, something like this will not work:

    

    Facebook fb = new Facebook("appid");
    AsyncFacebookRunner runner = new AsyncFacebookRunner(fb);
    fb.setAccessToken(access_token);
    fb.setAccessExpires(expires);
    runner.request("me", new FbRequestListener());

But something like this will work:

    

    Facebook fb = new Facebook("appid");
    fb.setAccessToken(access_token);
    fb.setAccessExpires(expires);
    AsyncFacebookRunner runner = new AsyncFacebookRunner(fb);
    runner.request("me", new FbRequestListener());

0

精彩评论

暂无评论...
验证码 换一张
取 消