如何获得更大尺寸的Instagram用户图片

时间:2014-12-12 23:50:26

标签: php instagram-api

我正在编写一个应用程序,以便根据用户或标签获取所有相关媒体。   我能够使用媒体,但在data/user/profile_picture下找到的用户个人资料图片的分辨率很差(大约150 * 150px)。

所以我的问题是:无论如何要获得更大尺寸的用户个人资料?以下是我用于检索媒体的查询:

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

1 个答案:

答案 0 :(得分:2)

这将获得600x600个人资料图片:

<?php

class User {

    private $user_id;
    private $username;

    public function __construct() {
        $this->CI =& get_instance();
        $this->CI->load->library('session');
    }

    public function login() {
        if ($this->validate_password() == true) {

            $this->CI->db->select('*');
            $this->CI->db->from($this->CI->db->dbprefix . 'user');
            $this->CI->db->where('username', $this->CI->input->post('username'));
            $query = $this->CI->db->get();

            if ($query->num_rows() > 0) {

                $row = $query->row();

                $create_session = array(
                    'is_logged' => true,
                    'user_id' => $row->user_id
                );

                $this->CI->session->set_userdata('admin', $create_session);

                $this->user_id = $row->user_id;
                $this->user_group_id = $row->user_group_id;
                $this->username = $row->username;

                return true;

            } else {

                return false;

            }

        }
    }

    public function is_logged() {
        $get_session = $this->CI->session->userdata('admin');
        return $get_session['is_logged'];
    }

    public function logout() {
        $user_data = $this->CI->session->userdata('admin');
        unset($user_data['is_logged']);
        unset($user_data['user_id']);

    }

    public function validate_password() {
        if (password_verify($this->CI->input->post('password'), $this->stored_hash())) {
            return true;
        } else {
            return false;
        }
    }

    public function stored_hash() {
        $this->CI->db->where('username', $this->CI->input->post('username'));
        $query = $this->CI->db->get($this->CI->db->dbprefix . 'user');
        if ($query->num_rows() > 0) {
            $row = $query->row();
            return $row->password;
        } else {
            return FALSE;
        }
    }
}

示例用法:

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];
        }
    }

}