【发布时间】:2014-02-18 02:33:13
【问题描述】:
我有一组 Facebook 用户,它们是使用自定义 Facebook 多选器输出的。
输出是选定用户的列表。
我如何获取这些 ID 号码,然后使用 Facebook API 将消息发布到他们的墙上?
【问题讨论】:
标签: javascript php facebook facebook-graph-api
我有一组 Facebook 用户,它们是使用自定义 Facebook 多选器输出的。
输出是选定用户的列表。
我如何获取这些 ID 号码,然后使用 Facebook API 将消息发布到他们的墙上?
【问题讨论】:
标签: javascript php facebook facebook-graph-api
下面是我之前使用的 PHP 代码 sn-p
$attachment = array(
'from' => $_SESSION['username'],
'access_token' => $access_token,
'message' => $message,
'name' => $title,
'link' => $url,
'description' => $description,
'caption' => $caption,
'picture' => $img,
'privacy' => json_encode(array('value' => 'FRIENDS_OF_FRIENDS'))
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/'.$userid.'/feed');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //to suppress the curl output
$result = curl_exec($ch);
curl_close ($ch);
确保您拥有为您的应用提供的有效访问令牌。
向您的用户请求“publish_stream”权限。
编辑:
这是发布到用户墙上的 JavaScript 方式
function fb_publish() {
FB.ui(
{
method: 'stream.publish',
message: 'Message here.',
attachment: {
name: 'Name here',
caption: 'Caption here.',
description: (
'description here'
),
href: 'url here'
},
action_links: [
{ text: 'Code', href: 'action url here' }
],
user_prompt_message: 'Personal message here'
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
}
【讨论】: