我使用此代码登录Instagram API,但在某些服务器中,此代码运行正常,在其他服务器中我无法获取Instagram数据。谁知道为什么?
<?php
require 'instagram.class.php';
require 'instagram.config.php';
// Receive OAuth code parameter
$code = $_GET['code'];
// Check whether the user has granted access
if (true === isset($code)) {
// Receive OAuth token object
$data = $instagram->getOAuthToken($code );
if(empty($data->user->username))
{
echo "1";
}
else
{
session_start();
$_SESSION['userdetails']=$data;
echo $user=$data->user->username;
echo $fullname=$data->user->full_name;
echo $bio=$data->user->bio;
echo $website=$data->user->website;
echo $id=$data->user->id;
echo $token=$data->access_token;
}
}
else
{
// Check whether an error occurred
if (true === isset($_GET['error']))
{
echo 'An error occurred: '.$_GET['error_description'];
}
}
?>
答案 0 :(得分:1)
如果您在服务器上创建会话,则无法在其他服务器上获取该会话。您需要使用粘性会话。我的建议是在你的一台服务器上安装memcache。您可以看到如何安装here。安装后,假设您的内存缓存服务器路径为localhost:11211
。您可以配置您的php,以便在此memcache服务器而不是每服务器内存中保存您的会话。您需要在php.ini
,
session.save_handler = memcache
session.save_path = "tcp://localhost:11211"
当您设置任何会话时,它将在此memcache服务器上创建,您可以从任何服务器获取它。此设置可应用于您的所有服务器。您需要在所有服务器中为session.save_path
提供服务器名称。因为,只有一个memcache服务器