问题
I've read through the documentation and I don't understand how to get the new code, I was doing this to get a token to read the feed for a site I'm an admin on:
https://graph.facebook.com/oauth/access_token?client_id=" + sClientID + "&client_secret=" + sSecret + "&redirect_uri=" + sRedirectURI + "&code=" + sCode;
and then:
"https://graph.facebook.com/" + sUser + "/accounts?" + sToken; To get the feed.
It's telling me:
{
"error": {
"message": "This authorization code has been used.",
"type": "OAuthException",
"code": 100
}
}
I know I need a new authorization code but cannot find the method to call to get one in the documentation. Alternatively, is there another way to get this feed?
回答1:
STEP 1: Please open your browser, type the following URL and hit.
https://www.facebook.com/v8.0/dialog/oauth?client_id={app_id}&redirect_uri={redirect_uri}
STEP 2: Let's assume your {redirect_uri} = https://www.abc.co.in/. Then you will receive new authorization code with the following format in the URL itself. https://www.abc.co.in/?code={get_new_auth_code_here}
STEP 3: Get the access token by the following URL with said new authorization code.
https://graph.facebook.com/oauth/access_token?client_id={app_id}&client_secret={app_secret}&grant_type=authorization_code&redirect_uri={redirect_uri}&code={newly_received_auth_code}
Cheer!
回答2:
You may need to re-read the login documentation: https://developers.facebook.com/docs/facebook-login/login-flow-for-web-no-jssdk/
You use the code
one time only, and exchange it for an access_token
- you then use the access token to make API calls on behalf of your users.
When the token expires (in approx 60 days) or the next time the user comes back to your app, you send the user through the login flow again, get a new code, and exchange that for a new token which will be valid for up to 60 days
来源:https://stackoverflow.com/questions/18854812/facebook-how-to-get-a-new-authorization-code-for-an-access-token