如何在 Graph API 中以页面所有者或管理员身份在 Facebook 粉丝页面上发布帖子 [英] How to publish a post on a Facebook Fan Page as Page Owner or Admin in Graph API

查看:36
本文介绍了如何在 Graph API 中以页面所有者或管理员身份在 Facebook 粉丝页面上发布帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个 PHP 项目,需要在 Facebook 主页上发布帖子.例如,我有一个电子商务网站.当我创建产品时,新产品的链接将在电子商务的 Facebook 页面上共享.现在我正在 Facebook Graph API 资源管理器工具 (https://developers.facebook.com/tools/资源管理器)以这种方式.

I am doing a PHP project that need to publish a post on a Facebook Page. For example, I have an e-commerce website. When I create a product, the link of the new product will be shared on the Facebook Page of the e-commerce . Now I am testing it on Facebook Graph API explorer tool (https://developers.facebook.com/tools/explorer) in this way.

  1. 我生成了一个具有正确权限的 access_token,尤其是(manage_pages 和 publish_actions).

  1. I generated a access_token with right permissions especially (manage_pages and publish_actions).

我将一个 HTTP POST 方法发送到这个 URL 和这个字段:

I send a HTTP POST method to this URL and with this fields:

  • 网址 - {page-id}/feed

  • URL - {page-id}/feed

字段 - mesasge={message} ,published=true , link={link}

fields - mesasge={message} , published=true , link={link}

当我去查看我的 Facebook 粉丝页面时,它只是作为访客帖子发布.我的意思是由访问者发布(Facebook 粉丝页面基于其打开的帐户)并且它不是以网站管理员或网站所有者的身份发布.该帖子不被视为由粉丝专页发布.

When I go and view my Facebook Fan Page, it is just posted as visitor post. I mean posted by visitor (account that the Facebook fan page is opened based on) and it is not posting as the site admin or site owner. The post is not considered as posted by Fan Page.

推荐答案

最后,经过大量测试,它可以工作,没有 PHP SDK.这是分步指南:

Finally, after a lot of tests, it worked, without the PHP SDK. This is the step by step guide:

Get permissions and the page token:

转到 https://developers.facebook.com/tools/explorer/ 和从左侧的第一个下拉菜单中选择您的应用.

Go to https://developers.facebook.com/tools/explorer/ and select your app from the first drop down menu, in the left.

点击获取访问令牌"按钮,在选择权限"窗口中,点击扩展权限",勾选manage_pages和publish_stream,点击获取访问令牌"蓝色按钮.

Click on the button "Get access token", and in the "Select Permissions" window, click in "Extended Permissions" and check manage_pages and publish_stream, and click in "Get Access Token" blue button.

在此步骤中,您可能会被要求授予应用访问 Facebook 帐户的权限,接受.

You may be asked in this step to garant permissions to your app to access to your Facebook account, accept.

接下来,单击GET"下拉菜单旁边的文本字段末尾,并替换以下数字:me/accounts,然后单击此文本字段旁边的蓝色按钮.

Next, click at the end of the text field next to the "GET" drop down, and replace the numbers for: me/accounts, and click in the blue button next to this text field.

您将获得所有页面的令牌,包括您的应用页面.在列表中找到您的页面名称,将如下所示:名称":您的页面名称"

You'll get the tokens for all your pages, including your app page. Find your page name in the list, will look like this: "name": "Your page name"

找到页面后,复制该页面的访问令牌(会很长),如下所示:"access_token": "XXXXXXXX".同时复制页面的id:id":XXXXX".

When you located your page, copy the access token for the page (will be really long), that can look like this: "access_token": "XXXXXXXX". Also copy the id of the page: "id": "XXXXX".

这一步到此结束,我们现在可以开始编码了.

That's all for this step, we can start coding now.

Post to your page wall via PHP

首先,对于这个脚本,你需要一个支持 curl 的服务器.

First, for this script, you'll need a server supporting curl.

我们开始定义页面访问令牌和我们在第一步中获得的页面 ID 的 PHP 文档:

We start the PHP document defining the page access token and the page id that we've get in the 1st step:

<?php
$page_access_token = 'XXXXXXX';
$page_id = 'YYYYYYYY';

之后,我们创建一个包含要发布到页面墙上的信息的数组:

After that, we create an array with the info to post to our page wall:

$data['picture'] = "http://www.example.com/image.jpg";
$data['link'] = "http://www.example.com/";
$data['message'] = "Your message";
$data['caption'] = "Caption";
$data['description'] = "Description";

您当然可以使用 https://developers 中描述的任何其他帖子参数.facebook.com/docs/reference/api/post/,如果您不需要上述一个或多个参数,您可以简单地将其删除.

You can of course, use any other post parameter described in https://developers.facebook.com/docs/reference/api/post/ and if you don't need one or many of the parameters above you can simply delete it.

好的,此时我们将访问令牌添加到数组中:

Ok, At this point we add to the array the access token:

$data['access_token'] = $page_access_token;

然后我们设置我们的帖子网址,以便在我们的页面上发布:

And we set our post url, to post in our page:

$post_url = 'https://graph.facebook.com/'.$page_id.'/feed';

最后一步,我们将使用 curl 在我们的页面墙中发布我们的消息:

And the last step, we'll use a curl to post our message in our page wall:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $post_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($ch);
curl_close($ch);
?>

之后,我们可以保存我们的php文档,并尝试执行它.该帖子可能会出现在我们的 Facebook 页面中.

After that, we can save our php document, and try to execute it. The post may appear in our Facebook page.

这篇关于如何在 Graph API 中以页面所有者或管理员身份在 Facebook 粉丝页面上发布帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆