Facebook PHP Api cUrl自动发布到页面墙(不是个人资料墙)

时间:2010-09-28 11:43:04

标签: php facebook

我需要能够发布到我的页面墙上,我已经发布了offline_permissions,我将其发布到我的个人资料墙,但我需要将其发布到我的页面墙上。

任何人都知道如何做到这一点,我的代码需要在哪里改变?感谢

<?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);

&GT;

1 个答案:

答案 0 :(得分:0)

$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/