8

I have finished my app and then tried it on 3 FB accounts and it was ok, but the 4th have a permanent error (it cannot get an access token):

com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: Expected 1 '.' In the input between the postcard and the payload.

I tried to remove the app and install it again on this account a few times and nothing changed.

I use Java and restFB client.

This is the code where i get the access token:

if (request.getParameter("code") != null) {
    String code = request.getParameter("code");
    String url = "https://graph.facebook.com/oauth/access_token?"
        + "client_id=" + clientId + "&" + "client_secret="
        + clientSecret + "&" + "code=" + code + "&" + "redirect_uri="
        + redirectURL +"&type=web_server";
    String accessToken=readUrl(url).split("&")[0].replaceFirst("access_token=", "");
    //....
}

I saw here someone with the same error, he said that the solution was:

replacing "|" with "%257C" which made my access token invalid"

I couldn't really understand what he means.

s4y
  • 50,525
  • 12
  • 70
  • 98
Talik
  • 103
  • 1
  • 5

4 Answers4

3

Embarrassing as it is -- I'll be honest in case it helps someone else:

When I got this error message, I had accidentally copy/pasted a Google access_token (e.g. ya29.A0A...) into a Facebook graph API route. :)

Jeff Ward
  • 16,563
  • 6
  • 48
  • 57
1

Check to ensure you are verifying the "code" parameter returned by Facebook before signing the request, not the "access token". That was the mistake I made.

Jason Washo
  • 536
  • 6
  • 22
1

It's probably worth logging the response to the /oauth/access_token request and the value you extract for use as the access token.

For the account that doesn't work, check whether the /oauth/access_token response includes other parameters before access_token. IIRC I've seen responses like

expiry=86400&access_token=AAAxxxx
Richard Barnett
  • 1,078
  • 9
  • 13
0

I experience the same issue, and after debugging my only conclusion was that when this message is thrown it might just be the token is expired or invalid. Checking with a freshly generated token should not throw this error.

edwardmp
  • 6,339
  • 5
  • 50
  • 77