简体   繁体   中英

Instagram liked API search with username and media_id

I need to find out user has been liked specific media or not

Like I have username and media_id as well as tag , and I need to find user has liked that media or not

I just wanted search in instagram database using username and media_id

Something like following

https://api.instagram.com/v1/media/555/likes?client_id=45b95681ac624228a40cddca1e087943&username=basedyl

https://api.instagram.com/v1/users/self/media/liked?access_token=38215261.f59def8.e202d307d1d64a70ac134b544eb8da3d&media_id=7007

As I looked into the liked API documentation, there no such option http://instagram.com/developer/endpoints/likes/

OR

I have also tried https://api.instagram.com/v1/media/555/likes?client_id=ABC

As I see, I need to fetch whole data and then do the array search.. I think which not cool..

Is there any easy way to solve this problem?

thanks in advanced

After long trial n error got this:

As I have media_id which I want to checked it liked by user not

and currently logged user access_token , so using following user I am able to find user has like that media or not

Please check description of following params

max_like_id = $media_id //Media ID

count=1 //I just want fetch and check only one media

access_token={$insta_access_token} //it give current user access_token

        $is_liked_url = "https://api.instagram.com/v1/users/self/media/liked?access_token={$insta_access_token}&count=1&max_like_id={$media_id}";

Ref: http://instagram.com/developer/endpoints/users/

GET/users/self/media/liked

Just use this: https://api.instagram.com/v1/media/MEDIA_ID?access_token=ACCESS-TOKEN

This will return all information about that media including the user_has_liked key, then check if it is true. I did this is Javascript using ajax so I'm not sure what the php code would be.

http://instagram.com/developer/endpoints/media/

I think you need to use Symmetric infinity for doing this.

A sample source code from the above reference..

require 'restclient'
require 'json'
media_url = "https://api.instagram.com/v1/users/self/media/liked/?access_token=ACCESS_TOKEN"
urls = []


while media_url != nil
  response = RestClient.get(media_url)
  json = JSON.parse(response)
 media_url = json["pagination"]["next_url"]
  json["data"].each do |item|
urls << item["images"]["standard_resolution"]["url"]


end



  sleep 0.2

end

urls.each_with_index do |url, idx|
  image = RestClient.get(url)

 path = Dir.pwd + "/#{idx}.jpg"

  File.open(path, 'w') {|f| f.write(image) }

end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM