Instagram how to get my user id from username?

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

    Working solution ~2018

    I've found that, providing you have an access token, you can perform the following request in your browser:

    https://api.instagram.com/v1/users/self?access_token=[VALUE]

    In fact, access token contain the User ID (the first segment of the token):

    <user-id>.1677aaa.aaa042540a2345d29d11110545e2499

    You can get an access token by using this tool provided by Pixel Union.

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

    Well you can just call this link

    http://jelled.com/ajax/instagram?do=username&username=[USER_NAME_GOES_HERE]&format=json

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

    Very late answer but I think this is the best answer of this topic. Hope this is useful.

    You can get user info when a request is made with the url below:

    https://www.instagram.com/{username}/?__a=1
    

    E.g:

    This url will get all information about a user whose username is therock

    https://www.instagram.com/therock/?__a=1
    

    Update i June-20-2019, the API is public now. No authentication required.

    Update in December-11-2018, I needed to confirm that this endpoint still work. You need to login before sending request to this site because it's not public endpoint anymore. The login step is easy also. This is my demo: https://youtu.be/ec5QhwM6fvc


    Update in Apr-17-2018, it's look like this endpoint still working (but its not public endpoint anymore), you must send a request with extra information to that endpoint. (Press F12 to open developer toolbar, then click to Network Tab and trace the request.)

    Sorry because I'm too busy. Hope this information help you guys. Hmm, feel free to give me a down-vote if you want.


    Update in Apr-12-2018, cameronjonesweb said that this endpoint doesn't work anymore. When he/she trying to access this endpoint, 403 status code return.


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

    Go to the api console & copy link https://api.instagram.com/v1/users/self in text field and authenticate using your instagram id & password, you will get your id in response

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

    Instead of using the API, one can examine the Instagram userpage to get the id. Example code in PHP:

    $html = file_get_contents("http://instagram.com/<username>");
    $doc = new DOMDocument();
    $doc->loadHTML($html);
    
    $xpath = new DOMXPath($doc);
    $js = $xpath->query('//body/script[@type="text/javascript"]')->item(1)->nodeValue;
    
    $start = strpos($js, '{');
    $end = strrpos($js, ';');
    $json = substr($js, $start, $end - $start);
    
    $data = json_decode($json, true);
    $data = $data["entry_data"]["UserProfile"][0];
    # The "userMedia" entry of $data now has the same structure as the "data" field
    # in Instagram API responses to user endpoints queries
    
    echo $data["user"]["id"];
    

    Of course, this code has to be adapted if Instagram changes its page format.

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

    Here is how you can retrieve your user id from a username:

    $url = "https://api.instagram.com/v1/users/search?q=[username]&access_token=[your_token]";
    $obj = json_decode(@file_get_contents($url));
    echo $obj->data[0]->id;
    
    0 讨论(0)
提交回复
热议问题