developer tip

Instagram 사용자 이름에서 내 사용자 ID를 얻는 방법은 무엇입니까?

optionbox 2020. 7. 24. 20:38
반응형

Instagram 사용자 이름에서 내 사용자 ID를 얻는 방법은 무엇입니까?


JSON을 사용하여 이미지 피드를 웹 사이트에 임베드하는 중입니다.이 피드를 검색하려면 URL에 사용자 ID가 필요합니다.

사용자 ID는 어디에서 찾을 수 있습니까?


매우 늦은 답변이지만 이것이이 주제의 가장 좋은 답변이라고 생각합니다. 이것이 유용하기를 바랍니다.

아래 URL로 요청하면 사용자 정보를 얻을 수 있습니다.

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

예 :

이 URL은 사용자 이름이 therock 인 사용자에 대한 모든 정보를 얻습니다.

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

6 월 20-2019 i로 업데이트하면 API가 공개됩니다. 인증이 필요하지 않습니다.

2018 년 12 월 11 일에서 업데이트 된이 엔드 포인트가 여전히 작동하는지 확인해야했습니다. 더 이상 공개 엔드 포인트가 아니므로이 사이트로 요청을 보내기 전에 로그인해야합니다. 로그인 단계도 쉽습니다. 이것은 내 데모입니다 : https://youtu.be/ec5QhwM6fvc


2018 년 4 월 17 일에 업데이트되었지만이 끝 점이 여전히 작동하는 것처럼 보이지만 (더 이상 공개 끝점은 아닙니다) 추가 정보가 포함 된 요청을 해당 끝점에 보내야합니다. F12 키를 눌러 개발자 도구 모음을 연 다음 네트워크 탭을 클릭하고 요청을 추적하십시오.

너무 바빠서 죄송합니다. 이 정보가 도움이 되길 바랍니다. 흠, 원한다면 자유롭게 투표 해주세요.


cameronjonesweb은 2018 년 4 월 12 일에서이 엔드 포인트가 더 이상 작동하지 않는다고 업데이트했습니다. 이 끝점에 액세스하려고하면 403 상태 코드가 반환됩니다.



찾으려는 사용자 이름과 액세스 토큰으로 브라우저에이 URL을 입력하십시오.

https://api.instagram.com/v1/users/search?q=[USERNAME]&access_token=[ACCESS TOKEN]

1/2016 API 변경으로 6 월 이후 대부분의 메소드가 더 이상 사용되지 않습니다.

아래는 나를 위해 일했습니다.

  • 크롬, 사파리 또는 파이어 폭스 등 브라우저에서 인스 타 그램에 액세스하세요.
  • 개발자 도구를 시작하고 콘솔 옵션으로 이동하십시오.
  • 명령 프롬프트에서 아래 명령을 입력하고 Enter 키를 누르십시오.

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

운이 좋으면 처음 시도 할 수 있습니다. 그렇지 않은 경우 인내심을 갖고 페이지를 새로 고친 후 다시 시도하십시오. 사용자 ID가 나타날 때까지 계속하십시오. 행운을 빕니다!!


USER ID 및 사용자 세부 정보를 쉽게 얻을 수 있습니다

https://api.instagram.com/v1/users/search?q= [ 사용자 이름] & client_id = [당신 APP 클라이언트 ID]

예를 들어 :

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

결과:

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


API를 사용하는 대신 Instagram 사용자 페이지를 검사하여 ID를 얻을 수 있습니다. 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"];

물론 Instagram이 페이지 형식을 변경하면이 코드를 수정해야합니다.


현재 사용자 이름에서 사용자 ID를 가져 오는 직접적인 Instagram API는 없습니다. GET / users / search API 를 호출 한 다음 결과를 반복하고 username필드 값이 사용자 이름과 같은지 여부를 확인한 다음을 가져옵니다 id.


Instagram 사용자 ID로 Instagram ID를 검색하기 위해이 도구를 작성했습니다 : Instagram User ID Lookup .

그것은 이용 파이썬의 Instagram API에 액세스하기 위해 라이브러리를 포함하고, 소스 코드에 링크 의 Instagram API의 다양한 구현 예를 도시한다 (장고를 작성).

업데이트 : Ruby on Rails 로의 포트에 대한 소스 코드가 추가되었습니다 .


위에서 언급 한 모든 해결책을 시도했지만 아무 효과가 없습니다. Instagram이 그들의 변화를 가속화했다고 생각합니다. 그러나 브라우저 콘솔 방법을 시도하고 약간 놀았고 사용자 ID를 제공하는이 명령을 찾았습니다.

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

프로필 페이지를 방문하여 콘솔에이 명령을 입력하면됩니다. 이 작업을 수행하려면 페이지를 새로 고쳐야 할 수도 있습니다. (저의 명성으로 인해 답변으로 게시해야했습니다)


Instagrams API로 변환 하려면을 사용해야 username합니다 id.

내가 정확하게 기억한다면 당신 users/search은 사용자 이름을 찾고 거기에서 ID를 얻는 데 사용합니다.


ID를 얻으려면 Instagram API users/self/feed엔드 포인트에 인증 된 요청을하십시오 . 응답에는 다른 데이터 중에서 사용자 이름과 사용자 ID가 포함됩니다.


Most of these answers are invalid after the 6/1/2016 Instagram API changes. The best solution now is here. Go to your feed on instagram.com, copy the link address for any of your pictures, and paste it into the textbox on that page. Worked like a charm.


Working solution without access token as of October-14-2018:

Search for the username:

https://www.instagram.com/web/search/topsearch/?query=<username>

Example:

https://www.instagram.com/web/search/topsearch/?query=therock

This is a search query. Find the exact matched entry in the reply and get user ID from the entry.


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


This can be done through apigee.com Instagram API access here on Instagram's developer site. After loging in, click on the "/users/search" API call. From there you can search any username and retrieve its id.

{
"data": [{
    "username": "jack",
    "first_name": "Jack",
    "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_66_75sq.jpg",
    "id": "66",
    "last_name": "Dorsey"
},
{
    "username": "sammyjack",
    "first_name": "Sammy",
    "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_29648_75sq_1294520029.jpg",
    "id": "29648",
    "last_name": "Jack"
},
{
    "username": "jacktiddy",
    "first_name": "Jack",
    "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_13096_75sq_1286441317.jpg",
    "id": "13096",
    "last_name": "Tiddy"
}]}


If you already have an access code, it can also be done like this: https://api.instagram.com/v1/users/search?q=USERNAME&access_token=ACCESS_TOKEN


Well you can just call this link

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


Although it's not listed on the API doc page anymore, I found a thread that mentions that you can use self in place of user-id for the users/{user-id} endpoint and it'll return the currently authenticated user's info.

So, users/self is the same as an explicit call to users/{some-user-id} and contains the user's id as part of the payload. Once you're authenticated, just make a call to users/self and the result will include the currently authenticated user's id, like so:

{
    "data": {
        "id": "1574083",
        "username": "snoopdogg",
        "full_name": "Snoop Dogg",
        "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg",
        "bio": "This is my bio",
        "website": "http://snoopdogg.com",
        "counts": {
            "media": 1320,
            "follows": 420,
            "followed_by": 3410
        }
}

If you are using implicit Authentication must have the problem of not being able to find the user_id

I found a way for example:

Access Token = 1506417331.18b98f6.8a00c0d293624ded801d5c723a25d3ec the User id is 1506417331

would you do a split single seperated by . obtenies to acces token and the first element


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":"..."}},

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;

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);

Here is a really easy website that works well for me:

http://www.instaid.co.uk/

Or you can do the following replacing 'username' with your Instagram username

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

Or you can login to your Instagram account and use google dev tools and look at the cookies that have been stored. 'ds_user_id' is your user ID

enter image description here


https://api.instagram.com/v1/users/search?q="[USERNAME]"&access_token=[ACCESS TOKEN]

Please notice the quotation marks.

This does not always return a valid result but more often than non-quoted one:

https://api.instagram.com/v1/users/search?q="self"&count=1&access_token=[ACCESS TOKEN] 

returns user "self" (id: 311176867)

https://api.instagram.com/v1/users/search?q=self&count=1&access_token=[ACCESS TOKEN]

returns user "super_selfie" (id: 1422944651)


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.


First Create an Application on Instagram and get Client Id for your application

http://instagram.com/developer/

Now just copy paste following Url into browser window by replacing your Username and your Client Id https://api.instagram.com/v1/users/search?q=[Your-username]&client_id=[Your-Client-Id]

you will get a Json Result containing General Information about your account along with your Numeric user Id

참고URL : https://stackoverflow.com/questions/11796349/instagram-how-to-get-my-user-id-from-username

반응형