Instagram从/ oauth / access_token获得空响应

时间:2015-08-17 14:12:27

标签: php instagram-api

我有一个小的PHP页面,它登录Instagram并下载用户照片。我第一次使用它并登录,没问题。通常,如果我稍后回来尝试,它不会要求我登录(我已经登录)但是,/ oauth / access_token的响应是空的。如果我使用浏览器后退按钮再试一次,一切正常。

这是我正在使用的代码。 apiData包含client_id等。

<?php

define('CLIENT_ID', 'xxxx');
define('CLIENT_SECRET', 'xxx');
define('REDIRECT_URL', 'xxxx');
define('AUTH_TOKEN_URL', 'https://api.instagram.com/oauth/access_token');
define('API_OAUTH_URL', 'https://api.instagram.com/oauth/authorize');


function fetchData($url, $apiData){

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,15);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
    curl_setopt($ch, CURLOPT_POST, count($apiData));
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($apiData));

    $result = curl_exec($ch);
    curl_close($ch); 
    return json_decode($result);
  }

0 个答案:

没有答案