我正在使用JSON在我的网站中嵌入我的图像提要,URL需要我的用户id,这样我就可以检索这个提要。
那么,我在哪里可以找到/获取我的用户id呢?
发布于 2012-11-27 22:49:41
在浏览器中输入此url以及您要查找的用户名和访问令牌。
https://api.instagram.com/v1/users/search?q=[USERNAME]&access_token=[ACCESS TOKEN]
发布于 2014-01-22 08:03:37
人们可以检查Instagram用户页面来获取id,而不是使用API。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改变了它的页面格式,这段代码必须进行调整。
发布于 2014-09-19 23:03:36
目前没有直接的Instagram API来从用户名中获取用户id。您需要调用GET /users/search接口,然后迭代结果,并检查username
字段的值是否等于您的用户名,然后获取id
。
https://stackoverflow.com/questions/11796349
复制相似问题