検索用語が常に完全なユーザー名になることがわかっている場合は、結果を単純に繰り返して、ユーザー名が検索クエリと完全に一致したときに停止できます。
また、アクセス トークンを公開しないでください。
これは、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
?>
実際、完全なユーザー名を検索している場合、ほとんどの場合、検索するたびに最初の結果が探しているものになる可能性があります。