zyzo
zyzo

Reputation: 355

How to get bigger size picture of Instagram user

I'm writing an application to get all the relevant media based to a user or a tag. I was able to the media but the resolution of the user's profile picture found under data/user/profile_picture is quite poor (around 150*150px).

So my question is : is there anyway to get a user profile's picture in a bigger size ? Here are the queries I use to retrieve the media :

https://api.instagram.com/v1/users/3/media/recent/?access_token=ACCESS-TOKEN

https://api.instagram.com/v1/tags/snow/media/recent?access_token=ACCESS-TOKEN

Upvotes: 0

Views: 1402

Answers (1)

Bora Demircan
Bora Demircan

Reputation: 86

This gets the 600x600 profile picture:

function Request($url) {

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
    curl_setopt($ch, CURLOPT_HEADER, 0);  

    $result = curl_exec($ch);

    curl_close($ch);

    return $result;

}

function get_value($username, $att, $accesstoken) {

    $url = "https://api.instagram.com/v1/users/search?q=" . $username . "&access_token=" . $accesstoken;

    if($result = json_decode(Request($url), true)) {
        if ($att == "full_name") {
            return preg_replace("/[^A-Za-z0-9 ]/", '',  $result['data'][0][$att]);
        } elseif ($att == "profile_picture") {
            $res = str_replace("s480x480", "s600x600", $result['data'][0][$att]);
            $res = str_replace("s320x320", "s600x600", $res); 
            $res = str_replace("s150x150", "s600x600", $res); 
            return $res; 
        } else {
         return $result['data'][0][$att];
        }
    }

}

Example Usage:

$profile_picture = get_value("USERNAME","profile_picture", "ACCESS_TOKEN");

Upvotes: 3

Related Questions