简体   繁体   English

如何从PHP服务器脚本在Facebook页面上自动发布?

[英]How to Publish on Facebook Page automatic from php server scripts?

My client has a e-commerce website where they sell their products and they also have facebook page for that website. 我的客户有一个电子商务网站,他们在其中销售产品,也有该网站的Facebook页面。 I want to to publish wall post on that page when ever the product price is reduced or new product is lunched. 每当产品价格降低或新产品午餐时,我都希望在该页面上发布贴子。 But i want to make this automatic, so i want to authorize facebook automatic, means that i don't want any login dialog box. 但是我想使它自动运行,所以我想自动授权Facebook,这意味着我不需要任何登录对话框。 the script should authorize itself. 该脚本应自行授权。 now the code i am using is as below but it ask me for log in. and also tell me which method is good(easy) to publish page wall post? 现在我正在使用的代码如下,但是它要求我登录。并且还告诉我哪种方法是好的(容易的)发布页面墙贴?

require 'API_Library/Facebook/src/facebook.php';
 $page_id = '111111111111111';
 $appId = '111111111111111';
 $appSecret = 'aaaaaaaaaaaaaaaaaaaaa22222222222';

 $facebook = new Facebook(array(
             'appId' => $appId,
             'secret' => $appSecret,
             'cookie' => true
         ));
 $session = $facebook->getAccessToken();

 $me = NULL;

 if($session)
 {
     try
     {
         $me = $facebook->api('/me');
         $facebook->api('me/feed', 'post', array(
             'message' => 'Hello World!'
         ));
     }
     catch(FacebookApiException $e)
     {
         echo $e->getMessage();
     }
 }

OUTPUT: (#200) The user hasn't authorized the application to perform this action 输出:(#200)用户未授权应用程序执行此操作

In order to post something to a page, you will need the administrator of the page to be authenticated with the application. 为了将某些内容发布到页面,您将需要使用该应用程序对页面的管理员进行身份验证。 You cannot post to a page without being authenticated. 未经身份验证,您无法发布到页面。 So there will be some user interaction required before you can set this up automatically. 因此,在您可以自动进行设置之前,需要进行一些用户交互。

The process would be as follows: 流程如下:

  1. Setup a Facebook App to get a App ID and app secret - you'll need this to query the API and post updates to the page 设置一个Facebook应用程序以获取应用程序ID和应用程序秘密-您将需要使用它来查询API并将更新发布到页面上
  2. As the page administrator, login to your app with the manage_pages permission. 作为页面管理员,以manage_pages权限登录到您的应用程序。
  3. After logging in, an API call to /me/accounts will give you an access_token to access the page and publish updates 登录后,对/me/accounts的API调用将为您提供一个access_token来访问页面并发布更新
  4. Using the page's accesss_token , you can then POST updates using /{page_id}/feed 然后,使用页面的accesss_token ,可以使用/{page_id}/feed进行POST更新

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM