I'm trying to get the access token for Facebook login, but got an error instead. All the answers that I found tell me about the wrong redirect_uri format. This is the error I got:
{
"error": {
"message": "Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "Ht12b5BKgRK"
}
}
And here is the redirect URI registered in Facebook App.
Steps that I do:
- https://graph.facebook.com/oauth/authorize?client_id=APP_ID&redirect_uri=http://127.0.0.1:8080/MyProject/Mapping&scope=user_posts&response_type=code
- This link redirect me to http://127.0.0.1:8080/MyProject/Mapping?code=GENERATED_CODE
- Then in the code i generate next URI: https://graph.facebook.com/oauth/access_token?client_id=549422435210997&redirect_uri=http://127.0.0.1:8080/MyProject/Mapping&client_secret=CLIENT_SECRET&code=GENERATED_CODE
- Requesting this URI gives me error instead of
access_token
I have tryied also redirect_uri=http://127.0.0.1:8080/MyProject/Mapping/
. Still no results.
Also, I have tied the same steps using restFB library for Java. And got the same error.
ScopeBuilder scopeBuilder = new ScopeBuilder();
scopeBuilder.addPermission(UserDataPermissions.USER_POSTS);
FacebookClient client = new DefaultFacebookClient(Version.LATEST);
String loginDialogUrlString = client.getLoginDialogUrl(APP_ID, "http://127.0.0.1:8080/MyProject/Mapping", scopeBuilder);
System.out.println(loginDialogUrlString);
System.out.println();
AccessToken appAccessToken = client.obtainAppAccessToken(APP_ID, APP_SECRET);
System.out.println(appAccessToken.getAccessToken());
System.out.println(appAccessToken.getTokenType());
//On this step i got the same error
AccessToken userAccessToken = client.obtainUserAccessToken(APP_ID, APP_SECRET, "http://127.0.0.1:8080/MyProject/Mapping/", appAccessToken.getAccessToken());
System.out.println(userAccessToken.getAccessToken());