简体   繁体   English

如何在“某些”服务器上从instagram获取数据

[英]How to get data from instagram on “some” servers

I am using this code to login on Instagram API, but in some servers this code runs correctly, in other servers I can't get the instagram data. 我正在使用此代码登录Instagram API,但在某些服务器中此代码正确运行,在其他服务器中我无法获取instagram数据。 Who knows why? 谁知道为什么?

<?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'];
}

}

?>

If you create session on a server, you cannot get it on other servers. 如果在服务器上创建会话,则无法在其他服务器上获取会话。 You need to use sticky sessions. 您需要使用粘性会话。 My suggesiton is installing memcache on one of your servers. 我的建议是在其中一台服务器上安装内存缓存。 You can see howto install here . 您可以在此处查看如何安装。 After installation, let say your memcache server path is localhost:11211 . 安装后,假设您的内存缓存服务器路径为localhost:11211 You can configure your php to say that save your session in this memcache server instead of per server memory. 您可以配置您的php来表示将会话保存在此内存缓存服务器中,而不是按服务器内存。 You need following simple conf in your php.ini , 您需要在php.ini遵循简单的conf,

session.save_handler = memcache 
session.save_path = "tcp://localhost:11211"

When you set any session, it will be created on this memcache server, and you can get it from any server. 当您设置任何会话时,它将在此Memcache服务器上创建,您可以从任何服务器上获取它。 This settings mus be applied to all your servers. 此设置将应用于您的所有服务器。 You need to give server name for session.save_path in all servers. 您需要为所有服务器中的session.save_path提供服务器名称。 Since, there is only one memcache server 由于只有一台Memcache服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM