Instagram API: Can i check if user is verified?

2019-04-30 08:38发布

问题:

I would like to know if there is any way to check if the user verification badge with the Instagram API?

I have saw that https://api.instagram.com/v1/users/{user-id} doesn't returns if the user is verified, but if you view the source code of a users page, you can see that it has a boolean that called isVerified key and it's value inside a json struct of the user.

Thanks!

回答1:

Ok, this is not a great answer but here is how I accomplished this same task. Once I have a username from the API I do the following regex on the source of their profile page:

$response = file_get_contents('https://instagram.com/'.$username);
if (preg_match('/"user":\{"username":"'.$username.'",.*?"isVerified":true\},"__path":".*?'.$username.'.*?"/s', $response) || preg_match('/<meta content=".*?official.*?account.*?" name="description" \/>/is', $response)) {
    print "VERIFIED USER!";
}

As I said before this is super hacky but the API currently doesn't provide an isVerified value. Until they do I am using this regular expression. It looks for "isVerified":true part of the JSON struct you referenced. (example: https://instagram.com/taylorswift)

We also added an additional check where if the meta content tag has "official account" in it then we assume it's official. (example: https://instagram.com/3doorsdown) We added this check because Instagram started doing verified accounts in 2014 and there are quite a few celebrities that haven't gotten a verified badge yet. It should pick up some of the pieces but could very well bring in false positives too.

NOTE: This solution will break if Instagram ever changes the JSON struct or meta tags on their pages so use at your own risk. We only needed a script to check a small amount of usernames for verified badges and I came up with this real quick. The best solution will be whenever they update their API.