Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FB error:Expected 1 '.' in the input between the postcard and the payload

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.

like image 359
Talik Avatar asked Dec 07 '11 22:12

Talik


3 Answers

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. :)

like image 127
Jeff Ward Avatar answered Oct 15 '22 00:10

Jeff Ward


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
like image 38
Richard Barnett Avatar answered Oct 15 '22 00:10

Richard Barnett


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.

like image 1
Jason Washo Avatar answered Oct 15 '22 01:10

Jason Washo