Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting a Malformed access token "t ​ype":"OAuthException","code":190
    text
    copied!<p>I am writing an android application to get the Facebook user albums and photos and display in my Android application. I have created a <strong>Facebook App with APP_ID 281846961912565</strong>.</p> <p>While creating the Facebook instance, I am passing this id as follows</p> <pre><code>facebook = new Facebook(APP_ID); </code></pre> <p>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.</p> <p>I'm using the access token to get the album ids using <code>facebook.request("https://graph.facebook.com/me/albums?access_token="+facebook.getAccessToken());</code></p> <p>Now I get <code>{"error":{"message":"Malformed access token ACCESSTOKENACCESSTOKEN?access_token=ACCESSTOKENACCESSTOKEN","t‌​ype":"OAuthException","code":190}}</code></p> <p>Can any of you please help me resolve this issue and point out what i am doing wrong. </p> <p>My code is as follows:</p> <pre><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; } </code></pre> <p>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. </p> <pre><code> 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(); } } </code></pre> <p>Later when I do a `private void getImagesFromUserAlbum() { facebook.getAccessToken();</p> <pre><code> JSONArray albumss = null; String response = null; try { response = facebook.request("me/albums"); </code></pre> <p>// `</p> <p>I get the error {"error":{"message":"Malformed access token ACCESSTOKEN?access_token=ACCESSTOKEN","type":"OAuthException","code":190}}</p> <p>Thanks for your help.</p> <p>The code above is now the working copy. Thanks to Bartek.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload