发布通过卷曲
Facebook页面墙我试图张贴到使用卷曲我的Facebook页面墙上,但我不断收到以下错误发布通过卷曲
The user hasn't authorized the application to perform this action
如何生成使用curl正确的访问令牌?如果你去这个网址http://developers.facebook.com/tools/explorer/
然后我可以把下面的https://graph.facebook.com/337588736279406/feed,这将显示出我的墙饲料的话,我可以改变这个发布和添加一个字段的信息内容,如果我再运行此我得到以下响应。
{
"error": {
"message": "(#200) The user hasn't authorised the application to perform this action",
"type": "OAuthException",
"code": 200
}
}
我必须做什么来授权我作为用户?
有人可以帮助我做到这一点。
<?php
function postify($arr) {
$fields_string = '';
foreach ($arr as $key => $value) {
$fields_string .= $key . '=' . $value . '&';
}
return rtrim($fields_string, '&');
}
$appid = 'app id';
$redirect_url = 'http://stickynote.users36.interdns.co.uk';
$app_secret = 'app secret';
$page_id = '337588736279406';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id='.$appid.'&redirect_uri='.$redirect_url.'&client_secret='.$app_secret.'&perms=publish_stream');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$output = explode("=", $output);
curl_close($ch);
$postdata = array(
'message' => 'this is a test message',
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/'.$page_id.'/feed?access_token='.$output[1].'');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, postify($postdata));
$check = curl_exec($ch);
print_r($check);
?>
为了能够发布内容,您必须将publish_stream
权限授予您的应用程序。
请求权限可以使用OAuth Dialog完成。
顺便说一句,如果您只是为了测试目的需要用户,您可以通过选择您的应用程序使用Explorer Tool,点击获取访问令牌并检查所需的权限。
更新:
您将无法张贴代表的应用程序,只有用户或页面适当access_token
的(对于网页时,需要manage_pages
和access_token
从user
accounts
连接)。 不需要在access_token
检索URL中指定perms
。应该在该步骤之前授予权限。
你需要获得一个页面访问令牌来做到这一点。
在它说documentation:
页的access_token
用来管理一个页面的的access_token。当你想执行一个充当页面的操作时,这被用于 。此访问 令牌通过使用manage_pages权限发出HTTP GET到/ USER_ID/accounts或 /PAGE_ID?fields = access_token来检索。获取 /USER_ID /帐户将返回除每个网页的 access_token之外用户具有管理访问权限的页面列表(包括应用程序配置文件 页面)。或者,通过使用manage_pages权限发出HTTP GET到 /PAGE_ID?fields = access_token(您的 必须特别通过字段= 参数请求access_token字段),才能获得单个特定页面的页面访问令牌 )。请参阅Page对象的文档以了解更多信息 信息
获得访问令牌后,您可以进行这些api调用。
1.你只需要这个,如果你想发布为它的页面f,它不需要作为用户发布。 2.您需要申请'publish_stream'才能发布内容。 – 2012-02-23 16:35:39
我该如何做到这一点可以帮助 – DCHP 2012-02-23 16:40:21
我已经发布了我的完整代码 – DCHP 2012-02-23 16:43:12
嗨多汁感谢回复我很高兴困惑我如何通过卷发返回访问令牌我可以运行你说的http:// www。 facebook.com/dialog/oauth/?scope=email,user_birthday,publish_stream&client_id=277938122277013&redirect_uri=http://stickynote.users36.interdns.co.uk&response_type=token这会返回我的url中的代码,然后我如何访问这通过curl – DCHP 2012-02-23 16:54:53