1

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?

Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
fizgig
  • 292
  • 2
  • 4
  • 22

2 Answers2

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!

Anupam
  • 47
  • 3
0

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

Igy
  • 43,710
  • 8
  • 89
  • 115
  • There is no user though, this is just the company's web sites getting the company's own feed, the code is the code I have for the profile that I am an administrator of. I can't be logging into four sites every 60 days and uploading new tokens. – fizgig Sep 17 '13 at 17:38
  • There's always a Facebook user that your app is acting on behalf of, even if it's the page admin themselves - if you're only fetching posts from publicly-visible pages, you could also use an App access token which won't expire: https://developers.facebook.com/docs/facebook-login/access-tokens/ – Igy Sep 17 '13 at 17:47
  • I made a reply that was apparently deleted. If I use an app token, I get this response: error: { message: "A user access token is required to request this resource.", type: "OAuthException", code: 102 }. To get the page token, I need a user token. I need to get this without a manual process, it is my Admin account only that I am accessing to get the page token. – fizgig Sep 17 '13 at 18:48
  • For a page's `/feed` connection? that shouldn't be the case -the docs explicitly state that any access token should work, this includes App Access Tokens - https://developers.facebook.com/docs/reference/api/page/#connections - i'm almost sure you're doing something wrong here, you should read the docs carefully and make sure you understand the data model better – Igy Sep 17 '13 at 18:50
  • Well, here's the feed with the app token link: https://graph.facebook.com/157942917849/feed?access_token=124263197590850|rUqb8Et_73RrMtqY2e71xlFxARE and here's the page token link I dug out manually from the graph api console: https://graph.facebook.com/157942917849/feed?access_token=CAABxBEfARUIBAIXgC0nOjEJEgyCqihG2CMg0gqQ7KJZBbjiayb2vw06lIIoCCeA9KOqhFZBYkRgKa0cFz4ZBNklXCZA0QmRG0Xx7ZBSxZCo5fFoyTOaim64doeiaZCVgwOMlaM9pABVuqqacZCaGdiyXu6IPTURC8l8E0iWhQB7sXUV84zgrf5Lz – fizgig Sep 17 '13 at 18:54
  • Any pointers as to what I am doing wrong are appreciated, I get an empty feed with the app token, with the page token I get the proper feed but I can't see a way to get the page feed without a user token, and I can't see a way to get a user token without a manual process. I was using an authorization code for years until recent changes broke it. I've read through the documentation multiple times but almost all cases require a user to be doing something, I've had this site live for years grabbing their page's feeds and putting it on their web sites, I don't see an example case for that. – fizgig Sep 17 '13 at 19:12
  • I see I can get certain pages feeds with the token, but not my site. I stumbled on this: http://stackoverflow.com/questions/12875142/cannot-retrieve-facebook-page-feed-through-opengraph , Is it because it's a brewery? – fizgig Sep 17 '13 at 20:07
  • Yes, if a page is restricted you must use a user access token from a user who meets the restrictions: http://stackoverflow.com/questions/11747155/use-facebook-app-access-token-to-get-age-restricted-page-data-through-graph-api/11749930#11749930 – Igy Sep 17 '13 at 22:19
  • So is there any way to automate that process without manually getting the user token every 60 days? – fizgig Sep 18 '13 at 12:24
  • No, that's pretty much the point of access tokens - to let you access data on behalf of a user with their consent, they need to come back every 60 days to refresh that token – Igy Sep 18 '13 at 16:06
  • Is there any way to get access token without facebook login redirect. I mean just through code by using some API? @lgy – Easwaramoorthy Kanagaraj Jan 07 '15 at 10:43
  • No, you need a real Facebook user to authorise your app, you can't just get access to a user's account without their interaction – Igy Jan 07 '15 at 19:09
  • no, it only gives you the `code` not `token`. however, the official page doesn't tell you the next step after getting the `code`. any idea? – newBike Mar 06 '17 at 07:46
  • It's in the question - it's the call to /oauth/access_token – Igy Mar 06 '17 at 13:28