如果您知道搜索詞永遠是滿的用戶名,你可以簡單地遍歷這些結果和停止時的用戶名是搜索查詢的精確匹配。
此外,千萬不要公開您的訪問令牌。
這是你會怎麼做它在PHP
<?php
function getInstaID($username)
{
$username = strtolower($username); // sanitization
$token = "InsertThatHere";
$url = "https://api.instagram.com/v1/users/search?q=".$username."&access_token=".$token;
$get = file_get_contents($url);
$json = json_decode($get);
foreach($json->data as $user)
{
if($user->username == $username)
{
return $user->id;
}
}
return '00000000'; // return this if nothing is found
}
echo getInstaID('aliciakeys'); // this should print 20979117
?>
其實,機會是,如果你正在尋找完整的用戶名,幾乎每次搜索它,第一個結果將是一個你會尋找。
肯定第一個結果總是你要找的結果是錯誤的。看看這個例子 - https://snap.apigee.com/1PuJeFw#content=request。當尋找「音樂」用戶時,這不是第一個結果。更甚者,它甚至不在結果集中,因爲它們僅限於一定數量的項目。 – ecdeveloper