我想使用Facebook PHP SDK v5自动发布到FAN PAGE。我有下面的代码成功发布到我自己的墙上,但如何更改代码以发布到我的粉丝页面?根据我的阅读,我需要传递粉丝页面的页面ID?
$params["message"] = 'test';
$params["link"] = 'https://example.com';
$params["picture"] = 'https://example.com/images/logo_hod.jpg';
$params["description"] = 'testtt';
$access_token = $accessToken;
try {
$response = $fb->post('/me/feed', $params, $access_token);
} 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();
echo 'Posted with id: ' . $graphNode['id'];
我尝试更换此行:
$response = $fb->post('/me/feed', $params, $access_token);
将此替换为粉丝页面ID:
$response = $fb->post('/229107363768165/feed', $params, $access_token);
并收到错误:
Graph returned an error: Unsupported post request.
更新:我还制作了应用程序" public"试图超越"不支持的帖子请求"错误。没有运气。
答案 0 :(得分:1)
我认为你的$ params不对。 我用这个:
$fb = new Facebook\Facebook([
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.2',
]);
$params = [
'link' => 'https://example.com',
'photo' => 'https://example.com/images/logo_hod.jpg',
'message' => 'A test post!',
];
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->post('/me/feed', $params, '{access-token}');
} 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;
}
Post Links Using the Graph API
我假设您已经获得了访问令牌,并且访问令牌必须具有 publish_actions 权限才能生效。