验证FACEBOOK应用程序-PHP [英] Authenticating a FACEBOOK Application - PHP
本文介绍了验证FACEBOOK应用程序-PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要先进行身份验证,然后才能发布到我自己的墙上,所以这是我的代码
i need to authenticate before posting to my own wall, so here is my code
function get_app_token($appid, $appsecret)
{
$args = array(
'grant_type' => 'client_credentials',
'client_id' => $appid,
'client_secret' => $appsecret
);
$ch = curl_init();
$url = 'https://graph.facebook.com/oauth/access_token';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);
return json_encode($data);
}
$token = get_app_token($appid, $appsecret);
$attachment = array('message' => '',
'access_token' => $token,
'name' => 'Attachment Name',
'caption' => 'Attachment Caption',
'link' => 'http://apps.facebook.com/xxxxxx/',
'description' => 'Description .....',
'picture' => 'http://www.google.com/logo.jpg',
'actions' => array(array('name' => 'Action Text',
'link' => 'http://apps.facebook.com/xxxxxx/'))
);
$result = $facebook->api('/me/feed/', 'post', $attachment);
我收到错误 OAuthException ,无效的OAuth访问令牌签名.
i got error OAuthException ,Invalid OAuth access token signature.
推荐答案
您可以直接从facebook对象的会话数组中获取access_token.
you can get access_token from session array of facebook object directly.
$session = $facebook->getSession();
$session['access_token'];
当然您需要被授权.如果未设置会话,则必须重定向到loginUrl
of course you need to be authorized. if session is not set you must redirect to loginUrl
$facebook->getLoginUrl(array('req_perms' => 'email,read_stream,publish_stream'));
// this will return url for your authorization
并请求您所需的权限.
这篇关于验证FACEBOOK应用程序-PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文