【问题标题】:New Instagram API requesting for tagged media by user id新的 Instagram API 请求按用户 ID 标记的媒体
【发布时间】:2016-06-02 20:59:44
【问题描述】:

我正在尝试创建一个像 Instagram 这样的网站,根据特定的标签检索用户的媒体,因此每个用户都有他/她自己的网页。

根据新的 Instagram API,我正在努力使用 access_tokens 请求媒体,我在下面有这段代码,但它根本不起作用,逻辑上它是正确的

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

这是我的完整代码,以防万一

   <?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

谁能告诉我我应该怎么做才能为每个使用我的应用程序的用户使用 access_tokens ?

【问题讨论】:

    标签: php api instagram


    【解决方案1】:

    您是否已从 instagram 批准您的应用程序的许可? Instagram 在 2016/6/1 更改了他们的 api 政策。

    【讨论】:

    • 我该怎么做?
    • 我已申请批准,但等待了将近 1 周,这正常吗!!!
    猜你喜欢
    • 1970-01-01
    • 2017-11-09
    • 2020-03-11
    • 1970-01-01
    • 1970-01-01
    • 2019-09-12
    • 2017-04-29
    • 2018-09-28
    • 1970-01-01
    相关资源
    最近更新 更多