【问题标题】:How can I post to the wall of a Facebook Fan Page using PHP and Open Graph API如何使用 PHP 和 Open Graph API 将帖子发布到 Facebook 粉丝专页的墙上
【发布时间】:2023-03-29 16:47:01
【问题描述】:

欢迎提供示例代码,我似乎无法在网上找到任何简单的示例。

【问题讨论】:

  • 我最近写了一篇关于这个的文章。您需要获得 extended_access 权限,并且本质上以经过身份验证的用户身份发布,该用户是页面的管理员。 typeoneerror.com/articles/post/…

标签: php facebook facebook-graph-api


【解决方案1】:

使用新的Facebook PHP-SDK,很容易做到这一点。

要求:

  1. Extended Permissions,看你的需要
  2. 页面 ID

现在正如我所说,根据您的要求,您可能需要offline_access、manage_pages,但目前这是最简单直接的方法:

下载PHP SDK后,在example.php文件中:

  • 获取publish_stream权限:

    <fb:login-button perms="publish_stream"></fb:login-button>  
    
  • 成功验证后,您可以像普通user 个人资料一样发布到页面墙上(并且也使用相同的选项,message, picture, link, name, caption, description, source):

    $page_id = '123456789';
    $feed_array = array(
        'message' => "Hello world!"
    );
    $page_post = $facebook->api("/$page_id/feed","post",$feed_array);
    

结果:

请注意,这种方法需要您是页面的管理员。

【讨论】:

  • 这是使用 Graph API 而不是 Open Graph。
  • 很多人可以在一个页面上拥有不同的角色,哪些角色可以授予应用程序管理facebook页面的权限。
【解决方案2】:

在此将 /me/feed/ 更改为您的页面 id,我没有尝试....只是检查

$attachment = array('message' => 'some meesgae',
        'name' => 'This is my demo Facebook application!',
        'caption' => "Caption of the Post",
        'link' => 'mylink.com',
        'description' => 'this is a description',
        'actions' => array(array('name' => 'Get Search', 'link' => 'google.com')) );
    $result = $facebook->api('/me/feed?access_token='.$access_token, 'post', $attachment);

【讨论】:

  • 你从哪里得到$access_token?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-22
  • 1970-01-01
  • 2010-11-25
相关资源
最近更新 更多