我正在使用fb:multi-friend-selector
向朋友发送邀请。一旦用户提交表单,其重定向到一个页面,我获取所选朋友的ID,以便发布到他们的墙上。我已经请求了offline_access
的授权,但是当页面加载时会丢弃Uncaught OAuthException错误。我如何使用access_token
?
$app_id = APP_ID;
$canvas_page = CANVAS_PAGE_URL;
$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page)
. "&scope=publish_stream,email,offline_access";
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
include 'resources/friendInvitationForm.php';
}
require '../src/facebook.php';
//// Create our Application instance.
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxx',
'cookie' => 'true'
));
$friends = (isset($_REQUEST["ids"]) ? $_REQUEST["ids"] : null);
$count = count($friends);
$attachment = array(
'message' => 'this is my message',
'name' => 'This is my demo Facebook application!',
'caption' => "Caption of the Post",
'link' => 'http://www.facebook.com/pages/Cosmetics/167231286678063'
. '?sk=app_233227910028874',
'description' => 'this is a description',
'picture' => 'http://mysite.com/pic.gif',
'actions' => array(array(
'name' => 'Get Search',
'link' => 'http://www.google.com'))
);
for($i = 0; $i <= $count; $i++)
{
$result = $facebook->api('/'.$friends[$i].'/feed/','post',$attachment);
}