简体   繁体   中英

Facebook PHP Api cUrl auto post to page's wall (not profile wall)

I need to be able to post to the wall of my page, i have given offline_permissions and I got it to post to my profile wall but I need it to post to my pages wall.

Anyone know how to do this, where does my code need changing? thanks

<?php session_start();

$fb_page_id = xxxxxxxxxxxxxxxx;
$fb_access_token = 'xxxxxxxxx|xxxxxxxxxxxxxxxxxx-xxxxxxxx|xxxxxxxxxxxxxxxxxxxxxxx';

$url = 'https://graph.facebook.com/'.$fb_page_id.'/feed';

$attachment =  array(
'access_token' => $fb_access_token,
'message' => 'message text',
'name' => 'name text',
'link' => 'http://domain.com/',
'description' => 'Description Text',
'picture'=>'http://domain.com/logo.jpg',
 );

 // set the target url
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,$url);
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
 curl_setopt($ch, CURLOPT_POST, true);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
 curl_setopt($ch, CURLOPT_HEADER,0);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 $go = curl_exec($ch);

 curl_close ($ch);

?>

$config = array(
    'appId' => 'YOUR_APP_ID',
    'secret' => 'YOUR_APP_SECRET',
    'allowSignedRequest' => false //optional but should be set to false for non-canvas apps
);

$facebook->api('/me/feed', 'POST',
    array(
      'link' => 'www.example.com',
      'message' => 'Posting with the PHP SDK!'
 ));

https://developers.facebook.com/docs/php/howto/postwithgraphapi/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM