Reputation: 2231
I am working on an app where the admin wants every new "post" that's created to go straight to a facebook fanpage that that was created for the website. Such as posting on the wall " has posted a new thread on " and gives the link to visit the thread.
I know how to post to a user's wall, but I am completely unsure of how to post to a certain page, since not every logged in user (using facebook integration by the way) is an admin and capable of doing so.
Normally, I would start with something as follows
$config = array();
$config['appId'] = $appId;
$config['secret'] = $appSecret;
$facebook = new Facebook($config);
However, that just doesn't work for posting to a page since pages don't have app ids or secrets as far as I can tell. Since I am not even sure how else to instantiate the facebook class at this point, I don't know how to go forward from here.
I can't seem to find any current documentation on this. Even Facebook's API page neglects to show an example with PHP.
Upvotes: 1
Views: 767
Reputation: 1250
I actually had to do this yesterday.
$facebook->setAccessToken($access_token);
$user = $facebook->getUser();
if ($user) {
try {
$page_id = 'page_id_goes_in_here';
$page_info = $facebook->api("/$page_id?fields=access_token");
You need to get an access token. To do this, do to the Graph Api Explorer and in the top right, select your application form the dropdown menu. Click 'Get Access Token'. A box pops up, go to the third tab and select 'manage_pages'.
In the query line below this, you can enter me/accounts and it will display all the apps. Here you can get the id to go in the page id.
Boom! Hopefully that makes sense and works for you
Upvotes: 1