facebook error 'Error validating verification code'

前端 未结 12 1760
清歌不尽
清歌不尽 2020-11-30 21:08

very strange error. i use gide http://developers.facebook.com/docs/authentication/. so i create request to fb and pass redirect_uri. i use test site on localhost. so if i pa

相关标签:
12条回答
  • 2020-11-30 21:53

    I'm not sure if it will help, but i would suggest to encode only values in the url. Not the whole thing. eg:

    redirect_uri='http://localhost/test_blog/index.php?r='.urlencode('site/oauth2');
    
    0 讨论(0)
  • 2020-11-30 21:54

    Had the same problem all day when testing with redirect_uri=http://localhost:8000 (encoded to http%3A%2F%2Flocalhost%3A8000)...

    Solution was simply to make sure to put the trailing slash / on the end of the uri. So redirect_uri=http://localhost:8000/ (encoded to http%3A%2F%2Flocalhost%3A8000%2F).

    Again, make sure the redirect_uri is identical for both requests.

    0 讨论(0)
  • 2020-11-30 21:56

    You don't really need to encode, just put the '/' at the end of your redirect_url and everything should be fine!

    0 讨论(0)
  • 2020-11-30 22:03

    From what I can see, the problem here is that the redirect_uri must end with '/' and not contain '?' or other special characters. I think that is why you are getting 'Error validating verification code'. This error only appears if you are using file_get_contents(), and not when using the facebook php library. This is the solution for php, don't know if this error appears in other SDK's.

    0 讨论(0)
  • 2020-11-30 22:08

    Struggled with this for a while. Since I didn't want a redirect, but the redirect parameter is required, my solution was to simply set it to nothing -

    ...&redirect_uri=&client_secret=...
    
    0 讨论(0)
  • 2020-11-30 22:09

    Part of the information given by Aaron Wheeler is incorrect.

    It is true that the 'redirect_uri' parameter must be identical in both requests, however it is perfectly possible to URL encode a regular URL and use that as the value for the 'redirect_url' parameter, so long as you're careful to further URL encode any inline URLs.

    For instance, you wish facebook to redirect to the following URL:

    http://www.mysite.com/Users/oAuthComplete?my_param_1=/Party/pants
    

    Attempting to redirect the user to

    'https://www.facebook.com/dialog/oauth?client_id=12345&redirect_uri='
    . urlencode('http://www.mysite.com/Users/oAuthComplete?my_param_1=/Party/pants');
    

    Will fail as /Party/Pants creates an invalid URL

    However, redirecting to

    'https://www.facebook.com/dialog/oauth?client_id=12345&redirect_uri='
    .urlencode('http://www.mysite.com/Users/oAuthComplete?my_param_1='
    .urlencode('/Party/pants'));
    

    Will work as expected.

    If you are using the returned the redrect_uri value in the second, authenticate application request, be sure to url encode again - the value is automatically URL decoded when populating the $_GET superglobal. - This is what tripped me up.

    'https://graph.facebook.com/oauth/access_token?client_id=12345&&client_secret=SECRET&code=1234567'
    .urlencode('http://www.mysite.com/Users/oAuthComplete?my_param_1='
    .urlencode($_GET['my_param_1']));
    

    P.s. In your actual code, I'd recommend using sprintf() rather than chaining string together like in my example, for better readability.

    0 讨论(0)
提交回复
热议问题