Joselo
Joselo

Reputation: 93

Publish to a page wall using javascript API with a specific user

I'm trying to build a custom post to publish to one of my app facebookpage. I saw in the facebook documentation, the "from" is just a readonly property? theres a way to doit?.

var request = {
     message: 'test 1234',
     access_token: ACCESS_TOKEN,
     from: { 
        id: MY_APP_ID, 
        category: "Other", 
        name: "My great app"
     }
};

FB.api('/' + UserPageId + '/feed', post, request);

But instead of the post come from my app, is comming from the "UID" that owns that page.

Upvotes: 3

Views: 2574

Answers (1)

Lix
Lix

Reputation: 47956

You have to retrieve an access token as your app. Follow the instructions on the facebook authentication documentation under the section App Login and you will retrieve the correct access token - use that token when making the calls to the api and any action will be executed on behalf of the app.

This is the url to query for an app access token.

https://graph.facebook.com/oauth/access_token?
 client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&
 grant_type=client_credentials


If you are wanting to publish stories on behalf of a PAGE the process is a little different (its also detailed in the link above). You have to grant the manage_pages permission :

https://www.facebook.com/dialog/oauth?
 client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=manage_pages&
 response_type=token

And then you can see a list of all the pages the user manages by querying this url :

https://graph.facebook.com/me/accounts?access_token=TOKEN_FROM_ABOVE

It'll give you a list of page names, page ids and page access tokens. Use those tokens to make calls to the graph api on behalf of a page.

Upvotes: 1

Related Questions