如何在Facebook专页发布后在图形API页所有者或管理 [英] How to publish a post on a Facebook Fan Page as Page Owner or Admin in Graph API

查看:192
本文介绍了如何在Facebook专页发布后在图形API页所有者或管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这样做,需要发布在一个Facebook页面后一个PHP项目。例如,我有一个电子商务网站。当我创建一个产品,新产品的链接,将在电子商务的Facebook页面共享。现在我正在测试它的Facebook图形API Explorer工具( https://developers.facebook.com/tool​​s/explorer )这种方式。


  

第1步


 我生成具有特别合适的权限的access_token(manage_pages和publish_actions)


  

第二步


 我发送一个HTTP POST方法到这个URL以及与此领域。网址 -  {页ID} /饲料场 -  mesasge = {}消息公布= TRUE,链接= {}链接

当我去查看我的Facebook粉丝专页。据刚刚发布的游客职。我的意思是张贴访问者(占了Facebook粉丝页面是基于打开),并且它不张贴作为网站管理员或者网站所有者。我的意思是张贴粉丝专页的帖子不考虑。所以,请帮助我。我怎样才能解决这个问题。请帮帮我吧。


解决方案

最后,大量的测试后,它的工作,没有PHP SDK。这是一步一步的指导:

 获取权限和页面标记:

转到 https://developers.facebook.com/tool​​s/explorer/ 并从第一个下拉菜单,在左边选择你的应用程序。

点击按钮获取访问令牌,并在选择权限窗口中,单击扩展权限,并检查manage_pages和publish_stream,然后单击获取访问令牌蓝色按钮。

您可能会被要求在这一步GARANT权限,您的应用程序访问您的Facebook帐户,接受了。

接下来,单击文本框的结尾旁边的获取下拉,并更换了号码。我/账户,并在蓝色的按钮,点击旁边的这个文本字段

您会得到您的所有页面,包括你的应用程序页面的标记。在列表中找到您的页面名称,会是这样的:姓名:你的网页名称

在位于您的网页,复制访问令牌的页面(会很长),可以是这样的:的access_token:XXXXXXXX的。也复制页面的id:ID:XXXXX

这是所有这一步,我们现在可以开始编码。

 发布到通过PHP你的页面墙

首先,对于这个脚本,你需要一台服务器支持卷曲。

我们开始,我们已经取得了第一步的PHP文件定义页面访问令牌和页ID:

 < PHP
$ page_access_token ='XXXXXXX';
$ PAGE_ID ='YYYYYYYY';

在这之后,我们创建一个数组的信息发布到我们的网页墙:

  $数据['图片'] =htt​​p://www.example.com/image.jpg;
$数据['链接'] =htt​​p://www.example.com/;
$数据['消息'] =您的信息;
$数据['标题'] =标题;
$数据['说明'] =说明;

您当然可以,使用 HTTPS描述的任何其他职位的参数://开发商.facebook.com /文档/参考/ API /后/ 的,如果你并不需要一个或多个你上面的参数,可以简单地将其删除。

好吧,在这一点上,我们添加到阵列的访问令牌:

  $数据['ACCESS_TOKEN'] = $ page_access_token;

和我们设定的网址后,在我们的网页发布:

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

和最后一步,我们将使用一个卷曲在我们的网页墙上张贴我们的信息:

  $ CH = curl_init();
curl_setopt($ CH,CURLOPT_URL,$ POST_URL);
curl_setopt($ CH,CURLOPT_POST,1);
curl_setopt($ CH,CURLOPT_POSTFIELDS,$数据);
curl_setopt($ CH,CURLOPT_RETURNTRANSFER,1);
$收益率= curl_exec($ CH);
curl_close($ CH);
?>

在这之后,我们可以节省我们的PHP文件,并尝试执行它。后可能会出现在我们的Facebook页面。

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 .

1st Step

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

2nd Step

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

URL - {page-id}/feed

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

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 . I mean the post is not considered as posted by Fan Page . So , please help me . How can I solve this problem . Please help me please .

解决方案

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:

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

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.

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

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"

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

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

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";

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';

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

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

这篇关于如何在Facebook专页发布后在图形API页所有者或管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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