Instagram gem API 示例——使用特定选项

发布于 2024-12-27 08:16:55 字数 1034 浏览 3 评论 0原文

我目前正在学习如何使用 Instagram 的 API,并一直在尝试 github 上提供的示例: https ://github.com/Instagram/instagram-ruby-gem

我克隆了他们的 sinatra 应用程序,它运行良好。但是,我希望能够使用提供的每个选项,例如用户搜索。

我工作的唯一照片提要是 user_recent_media(如下所示)和 media_popular。我通过简单地交换这两种方法来做到这一点。

Instagram 的 API 在其示例中展示了一个简单的 put 方法。我究竟如何才能让它发挥作用,以便我可以使用他们的所有选项,例如搜索、location_recent_media、follows 等?该示例中的哪些代码需要更改?

# Search for users on instagram, by name or username
puts Instagram.user_search("shayne sweeney")

# Get a list of media close to a given latitude and longitude
puts Instagram.media_search("37.7808851,-122.3948632")

get "/feed" do
  client = Instagram.client(:access_token => session[:access_token])
  user = client.user

  html = "<h1>#{user.username}'s recent photos</h1>" 
  for media_item in client.user_recent_media
    html << "<img src='#{media_item.images.thumbnail.url}'>"
  end
  html
end

I'm currently learning how to use Instagram's API and have been playing around with the example provided on github: https://github.com/Instagram/instagram-ruby-gem

I've cloned their sinatra app and it runs fine. However, I want to be able to use every option provided, for example, user search.

The only photo feeds that I've gotten to work has been user_recent_media as shown below and media_popular. I did so by simply swapping the two methods.

Instagram's API shows a simple puts method in their example. How exactly can I get that to work so that I can use all their options such as search, location_recent_media, follows, etc.? What code in that example needs to be changed?

# Search for users on instagram, by name or username
puts Instagram.user_search("shayne sweeney")

# Get a list of media close to a given latitude and longitude
puts Instagram.media_search("37.7808851,-122.3948632")

get "/feed" do
  client = Instagram.client(:access_token => session[:access_token])
  user = client.user

  html = "<h1>#{user.username}'s recent photos</h1>" 
  for media_item in client.user_recent_media
    html << "<img src='#{media_item.images.thumbnail.url}'>"
  end
  html
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文