获取畸形的访问令牌QUOT;吨YPE":" OAuthException"," code":190 [英] Getting a Malformed access token "t ​ype":"OAuthException","code":190

查看:145
本文介绍了获取畸形的访问令牌QUOT;吨YPE":" OAuthException"," code":190的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写一个Android应用程序获取用户的Facebook相册和照片,并显示在我的Andr​​oid应用程序。 我创建了一个的Facebook应用程序与APP_ID 281846961912565

I am writing an android application to get the Facebook user albums and photos and display in my Android application. I have created a Facebook App with APP_ID 281846961912565.

在创建Facebook的情况下,我通过这个ID如下:

While creating the Facebook instance, I am passing this id as follows

facebook = new Facebook(APP_ID);

使用这种情况下,我能够登录到我的FB账号后在Facebook上墙的消息编程。 登录后,我得到一个access_token。

Using this instance, I am able to login to my FB account post on messages on facebook wall programatically. After logging in, I get an access_token.

我使用的访问令牌使用,以获得专辑IDS <$c$c>facebook.request("https://graph.facebook.com/me/albums?access_token="+facebook.getAccessToken());

I'm using the access token to get the album ids using facebook.request("https://graph.facebook.com/me/albums?access_token="+facebook.getAccessToken());

现在,我得到 {错误:{消息:格式不正确的访问令牌ACCESSTOKENACCESSTOKEN?access_token=ACCESSTOKENACCESSTOKEN","t‌​ype":"OAuthException","$c$c":190}}

可以在任何的请你帮我解决这个问题,并指出了我在做什么错。

Can any of you please help me resolve this issue and point out what i am doing wrong.

我的code是如下:

    private static final String[] PERMISSIONS = new String[] { "publish_stream","user_photos" };
public boolean saveCredentials(Facebook facebook) {
    Editor editor = getApplicationContext().getSharedPreferences(KEY,
            Context.MODE_PRIVATE).edit();
    editor.putString(TOKEN, facebook.getAccessToken());
    editor.putLong(EXPIRES, facebook.getAccessExpires());
    return editor.commit();
}

public boolean restoreCredentials(Facebook facebook) {
    SharedPreferences sharedPreferences = getApplicationContext()
            .getSharedPreferences(KEY, Context.MODE_PRIVATE);
    facebook.setAccessToken(sharedPreferences.getString(TOKEN, null));
    facebook.setAccessExpires(sharedPreferences.getLong(EXPIRES, 0));
    return facebook.isSessionValid();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    facebook = new Facebook(APP_ID);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.facebook_dialog);
    String facebookMessage = getIntent().getStringExtra("facebookMessage");
    if (facebookMessage == null) {
        facebookMessage = "Test wall post";
    }
    messageToPost = facebookMessage;
}

R.layout.facebook_dialog是会弹出询问是否一个消息应该在Facebook或不能共享​​的对话框。如果是以下方法被调用。

R.layout.facebook_dialog is the dialog which pops up asking if a message should be shared on facebook or not. If yes the following method is called.

    public void share(View button) {
    if (!facebook.isSessionValid()) {
        loginAndPostToWall();
    } else {
        postToWall(messageToPost);
    }
}
   public void loginAndPostToWall() {
    facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH,
            new LoginDialogListener());
}
   class LoginDialogListener implements DialogListener {
    public void onComplete(Bundle values) {
        saveCredentials(facebook);
        if (messageToPost != null) {
            postToWall(messageToPost);
        }
    }

    public void onFacebookError(FacebookError error) {
        showToast("Authentication with Facebook failed!");
        finish();
    }

    public void onError(DialogError error) {
        showToast("Authentication with Facebook failed!");
        finish();
    }

    public void onCancel() {
        showToast("Authentication with Facebook cancelled!");
        finish();
    }
}

   public void postToWall(String message) {
    Bundle parameters = new Bundle();
    parameters.putString("message", message);
    parameters.putString("description", "topic share");
    try {
        facebook.request("me");
        String response = facebook.request("me/feed", parameters, "POST");
        Log.d("Tests", "got response: " + response);
        if (response == null || response.equals("")
                || response.equals("false")) {
            showToast("Blank response.");
        } else {
            showToast("Message posted to your facebook wall!");
        }
                    getImagesFromUserAlbum();
        finish();


    } catch (Exception e) {
        showToast("Failed to post to wall!");
        e.printStackTrace();
        finish();
    }
}

后来,当我做一个'私人无效getImagesFromUserAlbum(){         facebook.getAccessToken();

Later when I do a `private void getImagesFromUserAlbum() { facebook.getAccessToken();

    JSONArray albumss = null;
    String response = null;
    try {
        response = facebook.request("me/albums");

//`

我得到的错误 {错误:{消息:格式不正确的访问令牌ACCESSTOKEN access_token = ACCESSTOKEN?,类型:OAuthException,code:190}}

I get the error {"error":{"message":"Malformed access token ACCESSTOKEN?access_token=ACCESSTOKEN","type":"OAuthException","code":190}}

感谢您的帮助。

在code以上,现在的工作副本。由于鲍尔泰克。

The code above is now the working copy. Thanks to Bartek.

推荐答案

如果你看的错误页的文档中,你会看到,当你得到错误190 你应该授权/ reauthorise用户。

If you look at the Errors page in the documentation you will see that when you get error 190 you should authorise/reauthorise the user.

我怀疑这发生在你身上,因为你第一次登录,那么<一个href="http://stackoverflow.com/questions/14408889/in-android-how-to-add-user-photos-permission-to-get-the-facebook-album-photos">added权限来访问该专辑为您的应用程序,但没有注销并重新登录,因此,你需要获得一个新的访问令牌,该令牌授予新权限,您的应用程序。

I suspect that this happened to you because you first logged in, then added the permissions to access the albums to your application BUT did not log out and log back in. Hence, you need to obtain a new access token which will grant the new permissions to your application.

这篇关于获取畸形的访问令牌QUOT;吨YPE&QUOT;:&QUOT; OAuthException&QUOT;,&QUOT; code&QUOT;:190的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆