Instagram how to get my user id from username?

前端 未结 24 999
傲寒
傲寒 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:44

    Currently there is no direct Instagram API to get user id from user name. You need to call the GET /users/search API and then iterate the results and check if the username field value is equal to your username or not, then you grab the id.

    0 讨论(0)
  • 2020-11-30 17:45

    Most of the methods are obsolete since June, 1/2016 api changes

    Below worked for me,

    • access instagram on your browser say chrome, safari or firefox.
    • Launch developer tools, go to console option.
    • on command prompt enter below command and hit enter:

      window._sharedData.entry_data.ProfilePage[0].user.id
      

    If you are lucky, you will get at first attempt, if not, be patient, refresh the page and try again. keep doing until you see user-id. Good luck!!

    0 讨论(0)
  • 2020-11-30 17:47

    Easily Get USER ID and User Details

    https://api.instagram.com/v1/users/search?q=[ USER NAME ]&client_id=[ YOU APP Client ID ]

    For Example:

    https://api.instagram.com/v1/users/search?q=zeeshanakhter2009&client_id=enter_your_id

    Result:

    {"meta":{"code":200},"data":[{"username":"zeeshanakhter2009","bio":"http://about.me/zeeshanakhter","website":"http://zeeshanakhter.com","profile_picture":"http://images.ak.instagram.com/profiles/profile_202090411_75sq_1377878261.jpg","full_name":"Zeeshan Akhter","id":"202090411"}]}

    0 讨论(0)
  • 2020-11-30 17:47

    to get your id, make an authenticated request to the Instagram API users/self/feed endpoint. the response will contain, among other data, the username as well as the id of the user.

    0 讨论(0)
  • 2020-11-30 17:47

    I think the best, simplest and securest method is to open your instagram profile in a browser, view source code and look for user variable (ctrl+f "user":{") inside main javascript code. The id number inside user variable should be your id.

    This is the code how it looked in the moment of writing this answer (it can, and probably will be changed in future):

    "user":{"username":"...","profile_picture":"...","id":"..........","full_name":"..."}},
    
    0 讨论(0)
  • 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);
    
    0 讨论(0)
提交回复
热议问题