John Davidson

javascript - Get Instagram photos, count of likes and comment on website with jQuery or PHP

0 comments
Message:


How can I get all photos and count of likes and comments of some instagram user into the website?


I tried many plugins or Instagram API, but nothing works.
The plugins are only for 12 photos and don´t give me count of likes and comments.
I need just some simple ajax request which give me urls of photos , likes and comments, but most importantly of all posts on Instagram account.


If anyone know how to do it or just give me hint where to find documentation of it, I will be thankful.


Thanks for your advices.


EDITED


I tried someting like this


<!DOCTYPE html>
<html>
<head>
<title>Instagram API</title>

<script src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT"
crossorigin="anonymous"></script>
</head>
<body>
<div id="token-feed"></div>

<script>

var token = 'SHORT-LIVED-TOKEN', //there are my real values
username = 'MY-USERNAME', //there are my real values
num_photos = 4;

$.ajax({
url: 'https://api.instagram.com/v1/users/search',
dataType: 'jsonp',
type: 'GET',
data: {access_token: token, q: username},
success: function(data){
console.log(data);
$.ajax({
url: 'https://api.instagram.com/v1/users/' + data.data[0].id + '/media/recent',
dataType: 'jsonp',
type: 'GET',
data: {access_token: token, count: num_photos},
success: function(data2){
console.log(data2);
for(x in data2.data){
$('#token-feed').append('<img src="'+data2.data[x].images.thumbnail.url+'">');
}
},
error: function(data2){
console.log(data2);
}
});
},
error: function(data){
console.log(data);
}
});
</script>


</body>
</html>

But it shows me only this error:




My Answer:
You can use the Instagram API to retrieve photos, likes, and comments from a user's account. Here is an example of how you can do this using jQuery:

javascript
$.ajax({
url: 'https://api.instagram.com/v1/users/{user_id}/media/recent/?access_token=ACCESS_TOKEN',
dataType: 'jsonp',
success: function(response) {
var photos = response.data;
photos.forEach(function(photo) {
var photoUrl = photo.images.standard_resolution.url;
var likes = photo.likes.count;
var comments = photo.comments.count;

// Display the photo, likes, and comments on your website
$('#photos').append('');
$('#likes').append('

Likes: ' + likes + '

');
$('#comments').append('

Comments: ' + comments + '

');
});
}
});


In this code snippet, replace `{user_id}` with the user's Instagram ID and `ACCESS_TOKEN` with your own access token. You can generate an access token by registering your application on the Instagram Developer website.

Please note that the Instagram API has some limitations and restrictions, so make sure to read the documentation and comply with their terms of use.

Rate this post

5 of 5 based on 1863 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us