Java 如何获取 Instagram 个人资料图片?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50086945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get Instagram Profile Picture?
提问by user9717489
How to extract Instagram Profile picture using instagram API in android ? Or any other Method To extract Insta Profile Picture?
如何在android中使用instagram API提取Instagram个人资料图片?或任何其他方法来提取 Insta 个人资料图片?
回答by Ishara Madhawa
Using the Instagram API users endpoint(https://api.instagram.com/v1/users/{user-id}/?access_token=ACCESS-TOKEN
) you will receive a response like this one:
使用Instagram API 用户端点( https://api.instagram.com/v1/users/{user-id}/?access_token=ACCESS-TOKEN
) 您将收到如下响应:
{
"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
}
}
Using this you can get the profile picture.
使用它,您可以获得个人资料图片。
回答by Chhaileng
Use one of these URL
使用这些 URL 之一
NOTE: To get Instagram USER_ID
, use first URL with Instagram USERNAME
注意:要获取 InstagramUSER_ID
,请使用Instagram 的第一个 URLUSERNAME
Edit: If you use second URL, you need to put some user-agent with your request. This is How I do with cURL.
编辑:如果您使用第二个 URL,则需要在请求中放置一些用户代理。这就是我如何处理 cURL。
curl -s -H 'User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 12_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Instagram 105.0.0.11.118 (iPhone11,8; iOS 12_3_1; en_US; en-US; scale=2.00; 828x1792; 165586599)' https://i.instagram.com/api/v1/users/USER_ID/info/
回答by Rodrigo Vieira
To get profile photo, use the function bellow:
要获取个人资料照片,请使用以下功能:
function getPhoto(a) {
// validation for instagram usernames
var regex = new RegExp(/^(?!.*\.\.)(?!.*\.$)[^\W][\w.]{0,29}$/);
var validation = regex.test(a);
if(validation) {
$.get("https://www.instagram.com/"+a+"/?__a=1")
.done(function(data) {
// getting the url
var photoURL = data["graphql"]["user"]["profile_pic_url_hd"];
// update img element
$("#photoReturn").attr("src",photoURL)
})
.fail(function() {
// code for 404 error
alert('Username was not found!')
})
} else {
alert('The username is invalid!')
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img src="" id="photoReturn">
<br><br>
<input type="text" id="usernameInput">
<button onclick="getPhoto($('#usernameInput').val().trim())">Get profile photo</button>