3

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.

Kara
  • 6,115
  • 16
  • 50
  • 57
Joselo
  • 93
  • 1
  • 8

1 Answers1

1

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.

Lix
  • 47,311
  • 12
  • 103
  • 131
  • all-in-all, fun for the whole family. – Lix Nov 22 '11 at 19:28
  • I'm using the access token provided by facebook, thanks for note that. – Joselo Nov 22 '11 at 19:41
  • They are all provided by facebook. You should read the documentation link that I posted above. There are different types of access tokens. In order to post as your app, you have to use the correct access token. – Lix Nov 22 '11 at 19:44
  • I'm using *FB.login* with serveral perms, included manage_pages, also i get the access token from _FB.login_ callback (response.authResponse). I don't get a "permission denied" i can't change the *from* of the post. – Joselo Nov 22 '11 at 19:57
  • usually I would retrieve the access token with server side scripts, but you could just as easily make requests to those url's with javascript. What server side scripts are you using and are you using any form of javascript libraries? eg. jQuery... – Lix Nov 22 '11 at 20:43
  • I just use a service on my backend. I consume it using jQuery. I move some backend logic to the client-side. – Joselo Nov 23 '11 at 13:17
  • use the [jQuery AJAX](http://api.jquery.com/jQuery.ajax/) call to query the url to get the access token. – Lix Nov 23 '11 at 13:35
  • 1
    what your are suggesting is that i need a different access token to publish in the behalf of the page! :) i´ll try. – Joselo Nov 24 '11 at 22:07