我正在开发一个对Instagram进行身份验证的应用程序。我已经登录了,我正在获取我的#34;令牌"正确,但移动到我的网站中的另一个页面无法识别保存的会话信息。奇怪的是,在大约5-10分钟后,同一页面没有得到会话信息,突然间有了它。我正在使用
在session_start();
在每个页面的开头。下面是代码的几个片段:
session_start();
$token = false;
if (isset($_SESSION['access_token'])) {
// user authenticated -> receive and set token
$token = $_SESSION['access_token'];
} else {
// receive OAuth code parameter
$code = $_GET['code'];
// authentication in progress?
if (isset($code)) {
// receive and store OAuth token
$data = $instagram->getOAuthToken($code);
$token = $data->access_token;
$_SESSION['access_token'] = $token;
} else {
// check whether an error occurred
if (isset($_GET['error'])) {
echo 'An error occurred: ' . $_GET['error_description'];
}
}
}
// check authentication
if ($token === false) {
// authentication failed -> redirect to login
header('Location: index.php');
}
else {
// store user access token
$instagram->setAccessToken($token);
在我的下一页上,我在检查用户是否已登录时,我有这个代码:
session_start();
require_once 'instagram.class.php';
$instagram = new Instagram(array(
'apiKey' => 'xxxxxxxxxxxx'',
'apiSecret' => 'xxxxxxxxxxxx'',
'apiCallback' => 'xxxxxxxxxxxx'
));
// create login URL
$loginUrl = $instagram->getLoginUrl(array(
'basic',
'likes',
'relationships'
));
$instagram->getAccessToken($token);
$token = $_SESSION['access_token'];
第二页没有看到access_token或$ token。
作为一个FYI,我使用这个PHP包装器来进行这些函数调用:https://github.com/cosenary/Instagram-PHP-API