Instagram自我认证?

时间:2013-04-19 09:07:06

标签: php instagram

我正在尝试从我的Instagram-Feed获取照片,但每次我必须登录我的身份验证弹出窗口,尽管我使用来自数据库的访问令牌

//FIRST TIME
$array = array(
        'client_id'=>'XXX',
        'client_secret' => 'XXX',
        'grant_type' => 'authorization_code',
        'redirect_uri' => REDIRECT_URL,
        'code' => $_GET['code']
        );

    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch,CURLOPT_POSTFIELDS, $array);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $res = curl_exec($ch);
    $access_token = $res['access_token'];

    //SAVE ACCESS_TOKEN INTO DB 

    //NEXT TIME
    $url = 'https://api.instagram.com/v1/users/self/feed?access_token='.$db['access_token'].'&client_id='.$array['client_id'].'&client_secret='.$array['client_secret'];
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTPGET, 1); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $res = curl_exec($ch);

我做错了什么?

1 个答案:

答案 0 :(得分:0)

抱歉,上面的行中有一个错误。 我每次都请求code,此重定向会向我显示登录表单。

<强>之前:

if(!isset($_GET['code'])) {
    header('location: https://api.instagram.com/oauth/authorize/?client_id=xxx&redirect_uri='.REDIRECT_URL.'&response_type=code');
}else{
    $url = 'https://api.instagram.com/oauth/access_token/';
    // ...

<强>后:

if(!isset($_GET['code']) && !isset($access_token) ) {
    header('location: https://api.instagram.com/oauth/authorize/?client_id=xxx&redirect_uri='.REDIRECT_URL.'&response_type=code');
}else{
    $url = 'https://api.instagram.com/oauth/access_token/';
    // ...

现在工作正常。