我的FB-App有这个问题
我有2个文件.. 1)mainApp.php ..和.. 2)asyncApp.php ..(处理数据,提供内容和shit ..)
现在..
当用户登录时,一切正常..我获取访问令牌并将其保存到SESSION-Var ..(此处仅处理mainApp.php)..但是..
当我通过jquery.load()调用async.php时,例如..我总是得到 {“error”:{“message”:“格式错误的访问令牌.. oO
但令牌与我在mainApp.php中的FB相同...... :(
mainApp: 这样我就得到了令牌..
if(isset($_GET["code"])) {
$code = $_GET["code"];
$url = 'https://graph.facebook.com/oauth/access_token?client_id='.$appID.'&redirect_uri='.urlencode($appRedirectURI).'&client_secret='.$appSecret.'&code='.$code;
$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,$url);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,6);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
if(strpos($buffer, 'access_token=') === 0) {
//if you requested offline acces save this token to db for use later
$token = str_replace('access_token=', '', $buffer);
$_SESSION['fbToken'] = $token;
稍后我调用async.php,它应该在用户墙上做一个feed ..
$attachment = array(
'access_token' => $_SESSION['fbToken'],
'message' => 'dfdfdf',
'name' => 'sdfdsf',
'link' => 'http://www.mbla.de',
'description' => 'sdfdsf',
'picture'=> '',
'actions' => json_encode(array('name' => $action_name,'link' => $action_link))
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://graph.facebook.com/me/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);
如果有人可以帮助我,那将会很好..我现在已经忍受了将近2周...... :(
答案 0 :(得分:0)
欢迎使用Stack Overflow!
async.php
会发生什么情况,是否有效?print_r()
的内容为$_SESSION
,会填充什么?
查看附加的代码(async.php
),看起来您没有正确地将参数传递给Facebook。 curl选项CURLOPT_POSTFIELDS
不会将数组作为参数。相反,它应该构造为查询字符串:
curl_setopt($ch, CURLOPT_POSTFIELDS, 'param1=value¶m2=value¶m3=value');
为方便起见,我倾向于这样做:
curl_setopt($ch, CURLOPT_POSTFIELDS, htmlspecialchars(http_build_query(array(
"param1" => 'value',
"param2" => 'value',
"param3" => 'value'
))));