使用PHP直接发布Facebook动态流

3

我想在我的Facebook网站墙页面上发布流。

到目前为止,我已经成功通过我的应用程序页面发布了流,但我不想这样做,我想直接发布。

正如我之前所说,我想在我的Facebook网站墙页面上发布,而不是在应用程序墙页面上发布。

我找不到任何有用的东西……此外,如果可能的话,我希望使用PHP进行发布。如果不可能,那么我猜我将不得不使用js。无论如何,我该怎么做?

1个回答

5
这是我使用PHP的方法:
 //Note that you will need to have the access token which is what gives permission to write.
 function self_fb_post($to_uid,$acToken) {
    global $fb; //this is the fb object
    $result = false;
    $feed_dir = '/'.$to_uid.'/feed/';  //to the UID you want to send to
    $message_str =  'Why does facebook development not have decent support';
    $msg_body = array('access_token' => $acToken,   
                  'name' => 'My wall post',
                  'message' => $message_str,
                  'caption' => "www.mysite.com",
                  'link' => 'http://www.mysite.com',
                  'description' => 'A wall post which is used to express the frustration of working with crappy facebook developer documentation', 
                  'picture' => 'http://farm6.static.flickr.com/1111/some-pic.jpg',
                  'actions' => array(array('name' => 'My Site',
                              'link' => 'http://www.mysite.com'))
                  );

try {
            //this is the API call that does it all
    $result = $fb->api($feed_dir, 'post', $msg_body);
} 
catch (Exception $e) {       
    $err_str = $e->getMessage();
}


     return $result;
}

$to_uid是你想要发布到的Facebook用户的ID(无论是你自己的还是别人的)。 - Zigglzworth
它没有进入catch。它在这里卡住了 $result = $fb->api($feed_dir, 'post', $msg_body); - 这意味着我正在使用错误的访问令牌/用户ID,但我不认为是这样,或者我使用了错误的SDK,我也不认为是这样,因为我是从Facebook(GitHub)下载的。 - Ron
1
你的 Facebook 对象叫做 $fb 吗?这只是我给它起的名字,所以请确保你使用的是相同的名称。require_once("path_to/facebook.php"); $fb = new Facebook(array( 'appId' => '你的应用程序 ID', 'secret' => '你的密钥', 'cookie' => true, )); - Zigglzworth
所以你需要使用属于你的应用程序的访问令牌。 - Zigglzworth
你说我出现错误是因为我没有给应用程序publish_stream和offline_access权限,但我确实使用我的用户而不是网站给了这些权限。 - Ron
显示剩余23条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接