[英]How to get data from instagram on “some” servers
我正在使用此代码登录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'];
}
}
?>
如果在服务器上创建会话,则无法在其他服务器上获取会话。 您需要使用粘性会话。 我的建议是在其中一台服务器上安装内存缓存。 您可以在此处查看如何安装。 安装后,假设您的内存缓存服务器路径为localhost:11211
。 您可以配置您的php来表示将会话保存在此内存缓存服务器中,而不是按服务器内存。 您需要在php.ini
遵循简单的conf,
session.save_handler = memcache
session.save_path = "tcp://localhost:11211"
当您设置任何会话时,它将在此Memcache服务器上创建,您可以从任何服务器上获取它。 此设置将应用于您的所有服务器。 您需要为所有服务器中的session.save_path
提供服务器名称。 由于只有一台Memcache服务器
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.