SO community,
I am stuck in my attempt to have an application post automatically to my Facebook page.
These are the steps I took:
A) I authorized my application for all my facebook pages and granted permissions offline_access, publish_stream and manage_pages using
https://www.facebook.com/dialog/oauth?client_id=<app_id>&redirect_uri=<url>&scope=read_stream,publish_stream,manage_pages,offline_access,publish_actions
B) I requested the access token for the application with those permissions
https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=<app_id>&client_secret=<app_secure_key>&scope=manage_pages,offline_access,publish_stream
C) I now want to get the access token for the page to be able to do the final post using
https://graph.facebook.com/feed?<page_access_token>&message=test&id=<page_id>&method=post
however getting the page_access_token is where I am failing
This is the call I am trying
https://graph.facebook.com/<page_id>?fields=access_token&access_token=<app_access_token>
but instead of the page's access token I just get this back:
{
"id": "<page_id>"
}
Anyone has any insight what I am missing to get the .
/Thomas
We just managed to get this working in this past couple of days. Here's a summary. I apologize if I am detailing it beyond necessary but a couple of things you have done seem a bit wrong. To sum up your steps:
If you are doing step_A correct, which by the looks of the URL seems all right, then at the end of it you will receive a CODE (not the final access token). This will be a redirection using the redirect URL you sent in step A, so make sure your server is accepting a request for that redirectURL specified there. It will be in the form http://redirectURL?code=A_CODE_GENERATED_BY_SERVER
so doing params[code] should get you the CODE.
Step_B might be where you are slightly off. You have send the CODE from step_A back to the server. I see that you have set a scope
parameter again which is now not necessary (it was done in step_A). Step_B your request URL should look like
https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&client_secret=YOUR_APP_SECRET&code=THE_CODE_FROM_ABOVE
This time Facebook sends back a Response
not using the redirectURL though. If you have the correct Step_B request URI you can paste it in your browser location bar and the response will render in your browser itself. You can use an HTTPBuilder (that's what I am using) and capture this Response body. It is of the form access_token=<really_big_string>&expires=<time_to_live>
. Parse this response whichever way you prefer.
This is also an access_token (let's call it access_token_uno
) and I suppose there is some amount of things you can do using this. I haven't tried it myself though and so we proceed to Step_C. I suppose you already know your PageID
. You have to send back access_token_uno to Facebook in a URL of the form
https://graph.facebook.com/<PageID>?fields=access_token&access_token=<access_token_uno>
The response will be a JSON block of the form:
{
"access_token": <required_page_access_token>,
"id": <PageID>
}
Parse the JSON block and you are done.
The one minor detail to remember: The redirectURL has to remain the same in Step_A and Step_B else the thing fails. Also, I haven't yet tried with the offline_access
permission but I don't think the steps above will change even if that is the case.
You need to get https://graph.facebook.com/{userid}/accounts for a user with administrative rights to the page. Inside that you should find the access_token for the page.
http://developers.facebook.com/docs/authentication/#app-login
来源:https://stackoverflow.com/questions/7507228/cant-get-access-token-for-a-facebook-page-for-an-application-that-has-all-the-r