我有一个PHP网站,它有一个Facebook连接(Facebook-php-sdk),在我的索引页面上有一个Facebook登录按钮。登录按钮在我的cloud9开发阶段(桌面/移动)显示并运行。然后我把应用程序推到Heroku,登录按钮出现了,但是一旦他们点击了我的登录-callback.php,就崩溃了。
经过一番研究,我发现我需要推动我的: FACEBOOK_APP_ID=xxxxxxxxxxxxxxx \ FACEBOOK_SECRET=xxxxxxxxxxxxxxx
一旦我添加了那些配置-vars,我的登录按钮就在移动浏览器上消失了,桌面浏览器仍然在登录-callback.php页面上崩溃。我已经做了几天的调查,似乎找不到任何有关这方面的信息。
我的网站是https://nolarec.org或https://nolarec.herokuapp.com/
login-callback.php
<?php
session_start();
require_once __DIR__ . '/src/Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => 'xxxxxxxxxxxxxxx',
'app_secret' => 'xxxxxxxxxxxxxxx',
'default_graph_version' => 'v2.5'
]);
$helper = $fb->getJavaScriptHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
}
if (isset($accessToken)) {
$fb->setDefaultAccessToken($accessToken);
try {
$requestProfile = $fb->get("/me?fields=name,email");
$profile = $requestProfile->getGraphNode()->asArray();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
}
$_SESSION['name'] = $profile['name'];
setcookie('name', $profile['name'], time() + (3600 *2), "/");
header('location: ../');
exit;
} else {
echo "Unauthorized access!!!";
exit;
}fb.js
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
// The response object is returned with a status field that lets the
// app know the current login status of the person.
// Full docs on the response object can be found in the documentation
// for FB.getLoginStatus().
if (response.status === 'connected') {
// Logged into your app and Facebook.
window.location.replace('./fbapp/login-callback.php');
} else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app.
} else {
// The person is not logged into Facebook, so we're not sure if
// they are logged into this app or not.
}
}
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxxxxxxxxxxxx',
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.5' // use any version
});
};
// Load the SDK asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));相关的index.php片
<?php
session_start();
require_once('c9_config.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> Nola Rec Connect | New Orleans Recreational HUB</title>
<link rel="stylesheet" type="text/css" href="css/normalize.css">
<link href='https://fonts.googleapis.com/css?family=Alegreya+SC:700' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Crimson+Text' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="css/main.css">
<link rel="stylesheet" type="text/css" href="css/Responsive.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="./fbapp/fb.js"></script>
</head>
<body>
<header>
<a href="index.php" id="logo">
<h1>Nola Rec Connect </h1>
</a>
<nav>
<ul>
<a href="nav/calendar/calendar.php" >Calendar</a>
<a href="nav/about/about.php">About</a>
<a href="nav/contact/contact.php">Contact</a>
<a href="nav/map/map.php">Maps</a>
</ul>
</nav>
</header>
<h1><?php if (isset($_COOKIE['name'])) {echo $_COOKIE['name']; } ?></h1>
<?php if (isset($_COOKIE['name'])) { } else { ?><div class="fb-login-button" data-scope="public_profile,email" onlogin="checkLoginState();"></div><?php } ?>任何帮助都将不胜感激。
发布于 2016-02-01 17:02:44
看来我需要在Heroku中获得OAuth.io插件。一旦我设置了OAuth.io,我就把我的Facebook公钥加到普通tab.Then中,在"Integrated‘s“选项卡中测试连接。不是100%确定这是否修复了它,但它现在起作用。
https://stackoverflow.com/questions/35001339
复制相似问题