像Facebook页面通过Facebook SDK for PHP

时间:2015-05-04 09:49:11

标签: php facebook facebook-graph-api

我通过Facebook SDK for PHP发布了用户的facebook-timeline链接。

$example_link = "https://www.facebook.com/pages/Mark-Zuckerberg/112432568767916?fref=ts&rf=112845672063384";
$example_text = "Hello World";
$response = (new FacebookRequest(
//Post a message and a link to the users timeline
$session, 'POST', '/me/feed', array(
        'link' => $example_link,
        'message' => $example_text
                      )
                    ))->execute()->getGraphObject();

此示例将文本写入用户时间线" Hello World"链接到Mark Zuckerbergs Facebook页面。

我的问题是: 是否有可能,我不仅发布了一个有效的Facebook页面链接(例如马克扎克伯格),还喜欢它在同一步骤?

1 个答案:

答案 0 :(得分:0)

不是一步到位。您必须使用$response->id来使用/{post_id}/likes来创建帖子。

$example_link = "https://www.facebook.com/pages/Mark-Zuckerberg/112432568767916?fref=ts&rf=112845672063384";
$example_text = "Hello World";
$response = (new FacebookRequest(
    //Post a message and a link to the users timeline
    $session, 'POST', '/me/feed', array(
        'link' => $example_link,
        'message' => $example_text
        )
    ))->execute()->getGraphObject();

$responseLike = (new FacebookRequest(
    //Post a message and a link to the users timeline
    $session, 'POST', '/'. $response->id . '/likes'