Javascript fbs appID cookies不存在
我尝试与Facebook connect建立连接,但出现了一些错误 我对此链接也有类似的问题。Php$\u COOKIE找不到相关的COOKIEJavascript fbs appID cookies不存在,javascript,facebook,facebook-graph-api,Javascript,Facebook,Facebook Graph Api,我尝试与Facebook connect建立连接,但出现了一些错误 我对此链接也有类似的问题。Php$\u COOKIE找不到相关的COOKIE Notice: Undefined index: fbs_appID in /opt/lampp/htdocs/phpdeneme/index.php on line 10 Notice: Undefined index: sig in /opt/lampp/htdocs/phpdeneme/index.php on line 22 Warnin
Notice: Undefined index: fbs_appID in /opt/lampp/htdocs/phpdeneme/index.php on line 10
Notice: Undefined index: sig in /opt/lampp/htdocs/phpdeneme/index.php on line 22
Warning: file_get_contents(https://graph.facebook.com/me?access_token=) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /opt/lampp/htdocs/phpdeneme/index.php on line 30
<?php
define('FACEBOOK_APP_ID', 'APP_ID');
define('FACEBOOK_APP_SECRET','SECRET_ID');
function get_facebook_cookie($appID,$appSecret){
$args = array();
parse_str(trim($_COOKIE['fbs_' . $appID], '\\"'), $args);
ksort($args);
$payload = '';
foreach($args as $key=>$value){
if($key != 'sig'){
$payload .= $key . '=' . $value;
}
}
if(md5($payload . $appSecret) != $args['sig'])
return null;
return $args;
}
$cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_APP_SECRET);
$user = json_decode(file_get_contents('https://graph.facebook.com/me?access_token=' . $cookie['access_token']));
?>
<html>
<body>
<?php if($cookie){ ?>
Welcome <?= $user->name ?>
<?php } else { ?>
<fb: login-button></fb:login-button>
<?php } ?>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({appId: '<?= FACEBOOK_APP_ID ?>' , status: true, cookie: true, xfbml:true});
FB.Event.subscribe('auth.login',function(response){
window.location.reload();
});
</script>
</body>
</html>
注意:未定义索引:第10行/opt/lampp/htdocs/phpdeneme/index.php中的fbs_appID
注意:第22行的未定义索引:sig in/opt/lampp/htdocs/phpdeneme/index.php
警告:文件\u获取\u内容(https://graph.facebook.com/me?access_token=)[function.file get contents]:无法打开流:HTTP请求失败!HTTP/1.0 400第30行/opt/lampp/htdocs/phpdeneme/index.php中的错误请求
欢迎
init({appId:'',状态:true,cookie:true,xfbml:true});
FB.Event.subscribe('auth.login',函数(响应){
window.location.reload();
});
怎么了?少了什么?哪些fbs cookie未创建 您使用的是旧的oauth 1.0格式。你现在必须使用新的格式 PHP代码中的一个示例,应该足够接近,可以修改为js,只需很少的更改: 函数get_facebook_cookie() { $CI=&get_instance(); $app_id=$CI->config->item('facebook_app_id'); $application\u secret=$CI->config->item('facebook\u app\u secret'); 如果(isset($COOKIE['fbsr.$app_id])){ 列表($encoded_sig,$payload)=分解('.',$COOKIE['fbsr'.$app_id],2) }
这是从这里传来的,还有一些关于这个问题的小道消息。嗯……你在那里发布的其他错误呢?你的浏览器允许该网站在你的电脑上创建cookie吗?
$sig = base64_decode(strtr($encoded_sig, '-_', '+/'));
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
return null;
}
$expected_sig = hash_hmac('sha256', $payload,
$application_secret, $raw = true);
if ($sig !== $expected_sig) {
return null;
}
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=" . $app_id . "&client_secret=" . $application_secret. "&redirect_uri=" . "&code=" . $data['code'];
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$data['access_token'] = $params['access_token'];
return $data;
}else{
return null;
}