Vénizia
Vénizia

Reputation: 581

Replace "via Graph API Explorer" label by my application name

I am quite new in Facebook application development. I was playing the all day with "how to post a message on the wall of a page?". I finally succeeded but each message got "via Graph API Explorer". I tried to find how to change it to my application name without success. I tried to see if I could force the value of application in the api command but it did not take it into account. Maybe I miss something :( If someone can help, that would be great!


I am still quite confused. Let me try to explain what I want to do: I would like to automatically publish on a page (as the page) some event that are defined on a website (in a kind of agenda). What I miss, I think, is how everything is working together on Facebook side: 1. the login process: as the application will run in a cron, this should not display a login dialog box. 2. the access token: application or page one? 3. the permissions: from my understanding, I need manage_pages (and publish_stream) but not clear how this should be set.

Thx for any clarification and maybe a clear example :o)

Upvotes: 1

Views: 1568

Answers (2)

Vénizia
Vénizia

Reputation: 581

OK I think I have finally found the way to do it. I needed a page access code and not an application access code. The token must be generated outside the application as a long live one.

  • Get a code using:

https://www.facebook.com/dialog/oauth?client_id={app_id}&redirect_uri={my_url}&scope=manage_pages,publish_stream

app_id is your application ID my_url is your application URL scope is the permission you want to be granted

In the redirected URL, you will have a code parameter. Copy it.

  • Generate the user access code using:

https://graph.facebook.com/oauth/access_token?client_id={app_id}&redirect_uri={my_url}&client_secret={app_secret}&code={code}

app_secret is your application secret key code is the code from step 1

You will get as output the user access token. This one is a short live one.

  • convert the short live to a long live user access token using:

https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id={app_id}&client_secret={app_secret}&fb_exchange_token={short live access token}

Replace the "short live access token" by the one you got on step 2 You will get as output the infinite user access token.

  • Get the page access token (this one will be infinite access token as the user access token is now an infinite access token too):

https://graph.facebook.com/me/accounts?access_token={infinite user access token}

Replace the "infinite user access token" with the value you got on step 3.

This command will list all the pages you administer. The output contains the page access token you need in field "access_token". You can so use this token in any API command in your application.

The best of the best is to do all those steps via a server side program (PHP for me) as the application secret key should remain "secret".

Upvotes: 2

Igy
Igy

Reputation: 43816

You need the user to authorise your own App using one of the Login flows and grant you one of the publishing Permissions -

If it says 'via Graph API Explorer' on the posts your app makes you're using the access token you retrieved when you were testing the API using the Graph API Explorer tool, not one produced by your own app

Upvotes: 2

Related Questions