0

我正在尝试从我的 Instagram-Feed 获取照片,但每次我都必须登录我的 Authentication-Popup,尽管我使用来自 DB 的访问令牌

//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);

我究竟做错了什么?

4

1 回答 1

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/';
    // ...

现在它工作正常。

于 2013-04-19T09:39:23.083 回答