[英]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.