循环访问数据库以发布到Facebook页面

时间:2017-07-03 17:38:36

标签: php facebook

我对此非常陌生,所以如果这有一个简单的解决方案我会道歉。

我每12小时运行一次文件,在数据库中搜索新条目。如果有新条目,则会将其发布到Facebook页面。它有效,但即使查询中有两个或更多,它也只发布一个条目。

可能只是因为我在错误的地方发表了if声明,但我只是试图弄清楚它。

我很感激任何建议或教程链接。

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc() ) {
        $linkData = [
            'link' => $url,
            'message' => 'Thank you for the positive review!' . "\r\n\r\n" . '"' . $row["review"],
        ];

        try {
             $response = $fb->post('/me/feed', $linkData, $pageAccessToken);
        } catch(Facebook\Exceptions\FacebookResponseException $e) {
             echo 'Graph returned an error: '.$e->getMessage();
             exit;
        } catch(Facebook\Exceptions\FacebookSDKException $e) {
             echo 'Facebook SDK returned an error: '.$e->getMessage();
             exit;
        }
        $graphNode = $response->getGraphNode();
    }
}

0 个答案:

没有答案