doubeng9407 2016-06-02 20:59
浏览 51

新的Instagram API按用户ID请求标记的媒体

I am trying to create a website like Instagram where user's media are retrieved according to a specific hashtag, so every user has his/her own web page.

according to new Instagram API I'm struggling to request media using access_tokens , I have this code below but it is not working at all, logically it is correct

// function to print out images
function printImages($userID){
$url = 'https://api.instagram.com/v1/users/'.$userID.'/media/recent/?         access_token='.$_GET['code'].'&count=5';
$instagramInfo = connectToInstagram($url);
$results = json_decode($instagramInfo, true);

//parse through the images one by one
foreach($results['data'] as $items){
$image_url = $items['images']['low_resolution']['url']; // goining through all result and give back url of picture to save it on the php serve.
echo '<img src" '. $image_url .' "/><br/>';
}

and here is my full code in case

   <?php

//config for user PHP server
set_time_limit(0);
ini_set('default_socket_timeout', 300);
session_start();


//Make constraints using define.
define('clientID', 'my client id I have removed it');
define('clientSecret', 'my secret I have removed it');
define('redirectURI', 'my url removed too for the question');
define('ImageDirectory', 'pics/');

// function that is going to connect to instagram.
function connectToInstagram($url){
    $ch = curl_init();

    curl_setopt_array($ch, array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_SSL_VERIFYPEER => false,
        CURLOPT_SSL_VERIFYHOST => 2,
        ));
    $result = curl_exec($ch);
    curl_close($ch);
    return $result; 
}


if (isset($_GET['code'])){
    $code = ($_GET['code']);
    $url = 'https://api.instagram.com/oauth/access_token';
    $access_token_settings = array ('client_id' => clientID,
                                    'client_secret' => clientSecret,
                                    'grant_type' => 'authorization_code',
                                    'redirect_uri' => redirectURI,
                                    'code' => $code
                                    );


    //function to get userID cause username doesn't allow uss to get pictures
function getUserID($userName){
    $url = 'https://api.instagram.com/v1/users/search?q='.$userName.'&access_token='.$_GET['code'];
    $instagramInfo = connectToInstagram($url);
    $results = json_decode($instagramInfo, true);
    echo $results['data']['0']['id'];
}

// function to print out images
function printImages($userID){
$url = 'https://api.instagram.com/v1/users/'.$userID.'/media/recent/?access_token='.$_GET['code'].'&count=5';
$instagramInfo = connectToInstagram($url);
$results = json_decode($instagramInfo, true);

//parse through the images one by one
foreach($results['data'] as $items){
    $image_url = $items['images']['low_resolution']['url']; // goining through all result and give back url of picture to save it on the php serve.
    echo '<img src" '. $image_url .' "/><br/>';
}

}

//cURL is what we use in PHP , it's a library calls to other API's.
$curl = curl_init($url); //setting a cURL session and we put in $url because that's where we are getting the data from
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $access_token_settings); // setting the POSTFIELDS to the array setup that we created above.
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // setting it equal to 1 because we are getting strings back
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // but in live work-production we want to set this to true for more security



$result = curl_exec($curl);
curl_close();

$results = json_decode($result, true);
$use

could anyone tell me what should I do to use access_tokens for every user using my app ?

  • 写回答

1条回答 默认 最新

  • dongying195959 2016-06-03 07:25
    关注

    Have you approved permission of your app from instagram? Instagram has changed their api policy on 2016/6/1.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP