Instagram how to get my user id from username?

前端 未结 24 1062
傲寒
傲寒 2020-11-30 17:14

I\'m in the process of embedding my image feed in my website using JSON, the URL needs my user id so I can retrieve this feed.

So, where can I find/get my user id?

24条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 17:49

    You can do this by using Instagram API ( User Endpoints: /users/search )

    how-to in php :

    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 GetUserID($username, $access_token) {
    
        $url = "https://api.instagram.com/v1/users/search?q=" . $username . "&access_token=" . $access_token;
    
        if($result = json_decode(Request($url), true)) {
    
            return $result['data'][0]['id'];
    
        }
    
    }
    
    // example:
    echo GetUserID('rathienth', $access_token);
    

提交回复
热议问题