Reputation: 779
Question 1:
I have only Instagram comment-id, is it possible to retrieve its original media-id?
Question 2:
Using instagram media-id, through http.call (GET), collecting comments of the specific media-id
Let's say the totalMediaCount is 33.
for(i=0; i<totalMediaCount; i++) {
HTTP.call('GET', 'https://api.instagram.com/v1/media/' + media-id[i] + '/comments?access_token=' + instagramAccessToken, {}, function(error, response) {
if (error) {
console.log(error);
} else {
//console.log(response);
console.log(i);
});
}
The result is:
33
33
33
33 ...
33
33
Which I expect to have the result like this:
0
1
2
3
4
5
...
30
31
32
What is the issue?
Upvotes: 1
Views: 1449
Reputation: 12952
cannot get media_id
from a comment_id
, no APIs for it
HTTP.call
is asynchronous, so the for
is loop is complete by the time the first HTTP.call is executed.
try this:
for(i=0; i<totalMediaCount; i++) {
var index = i;
HTTP.call('GET', 'https://api.instagram.com/v1/media/' + media-id[index] + '/comments?access_token=' + instagramAccessToken, {}, function(error, response) {
if (error) {
console.log(error);
} else {
//console.log(response);
console.log(index);
});
}
Upvotes: 1