简体   繁体   English

使用PHP SDK安排Facebook页面上的帖子

[英]Schedule posts on Facebook page with PHP SDK

I am trying to schedule wall posts to be added to the Facebook business page in the future. 我正在尝试安排将来要添加到Facebook业务页面的留言墙。

As far as I can see Facebook does not recommend to use "offline_access" anymore. 据我所知,Facebook不建议再使用“ offline_access”。

How would you do that? 你会怎么做?

This is my code so far. 到目前为止,这是我的代码。 It works if I am already logged into Facebook. 如果我已经登录了Facebook,它会起作用。

EDIT: Naturally I will create some code that check the schedule that I pull from the database. 编辑:自然,我将创建一些代码来检查我从数据库中提取的计划。 And use a cron job to regulary check that schedule. 并使用Cron作业定期检查该计划。

require_once('src/facebook.php');

$config = array(
    'appId'  => 'xxxxxxx',
    'secret' => 'xxxxxxx',
);

$facebook = new Facebook($config);
$user_id = $facebook->getUser();

$page_info = $facebook->api("/PAGE_ID?fields=access_token");

try {
    $ret_obj = $facebook->api('/PAGE_ID/feed', 'POST',
    array (
        'link' => 'http://www.example.com/',
        'message' => 'This is a test',
        'access_token'  => $page_info['access_token']
    ));
} catch(FacebookApiException $e) {
    $login_url = $facebook->getLoginUrl( array(
        'scope' => 'publish_stream'
    ));

    print_r($e->getType());
    print_r($e->getMessage());
}

You have to extend access_token periodically now. 您现在必须定期扩展access_token。 All other code should be working fine as previously 所有其他代码应能像以前一样正常工作

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

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