Instagram API用于获取具有特定主题标签的图片

时间:2012-11-01 12:48:36

标签: api tags instagram

我希望使用PHP从Instagram获取具有特定哈希标记的所有图片。我怎么能这样做?

3 个答案:

答案 0 :(得分:15)

首先,Instagram API端点“标签”需要OAuth身份验证。

您可以使用以下网址

查询特定主题标签(在本例中为雪)的结果

速率限制为每小时5000(X-Ratelimit-Limit:5000)

https://api.instagram.com/v1/tags/snowy/media/recent

样本回复

{
  "pagination":  {
    "next_max_tag_id": "1370433362010",
    "deprecation_warning": "next_max_id and min_id are deprecated for this endpoint; use min_tag_id and max_tag_id instead",
    "next_max_id": "1370433362010",
    "next_min_id": "1370443976800",
    "min_tag_id": "1370443976800",
    "next_url": "https://api.instagram.com/v1/tags/snowy/media/recent?access_token=40480112.1fb234f.4866541998fd4656a2e2e2beaa5c4bb1&max_tag_id=1370433362010"
  },
  "meta":  {
    "code": 200
  },
  "data":  [
     {
      "attribution": null,
      "tags":  [
        "snowy"
      ],
      "type": "image",
      "location": null,
      "comments":  {
        "count": 0,
        "data":  []
      },
      "filter": null,
      "created_time": "1370418343",
      "link": "http://instagram.com/p/aK1yrGRi3l/",
      "likes":  {
        "count": 1,
        "data":  [
           {
            "username": "iri92lol",
            "profile_picture": "http://images.ak.instagram.com/profiles/profile_404174490_75sq_1370417509.jpg",
            "id": "404174490",
            "full_name": "Iri"
          }
        ]
      },
      "images":  {
        "low_resolution":  {
          "url": "http://distilleryimage1.s3.amazonaws.com/ecf272a2cdb311e2990322000a9f192c_6.jpg",
          "width": 306,
          "height": 306
        },
        "thumbnail":  {
          "url": "http://distilleryimage1.s3.amazonaws.com/ecf272a2cdb311e2990322000a9f192c_5.jpg",
          "width": 150,
          "height": 150
        },
        "standard_resolution":  {
          "url": "http://distilleryimage1.s3.amazonaws.com/ecf272a2cdb311e2990322000a9f192c_7.jpg",
          "width": 612,
          "height": 612
        }
      },
      "users_in_photo":  [],
      "caption":  {
        "created_time": "1370418353",
        "text": "#snowy",
        "from":  {
          "username": "iri92lol",
          "profile_picture": "http://images.ak.instagram.com/profiles/profile_404174490_75sq_1370417509.jpg",
          "id": "404174490",
          "full_name": "Iri"
        },
        "id": "471425773832908504"
      },
      "user_has_liked": false,
      "id": "471425689728724453_404174490",
      "user":  {
        "username": "iri92lol",
        "website": "",
        "profile_picture": "http://images.ak.instagram.com/profiles/profile_404174490_75sq_1370417509.jpg",
        "full_name": "Iri",
        "bio": "",
        "id": "404174490"
      }
    }
}

你可以在这里玩:

https://apigee.com/console/instagram?req=%7B%22resource%22%3A%22get_tags_media_recent%22%2C%22params%22%3A%7B%22query%22%3A%7B%7D%2C%22template%22%3A%7B%22tag-name%22%3A%22snowy%22%7D%2C%22headers%22%3A%7B%7D%2C%22body%22%3A%7B%22attachmentFormat%22%3A%22mime%22%2C%22attachmentContentDisposition%22%3A%22form-data%22%7D%7D%2C%22verb%22%3A%22get%22%7D

您需要将“身份验证”用作OAuth 2,系统会提示您通过Instagram登录。 发布您可能需要重新命名“模板”部分中的“标记名称”。

所有与分页相关的数据都可以在响应中的“分页”参数中找到,并使用它的“next_url”来查询下一组结果。

答案 1 :(得分:11)

目前还无法使用多个代码搜索内容,因为现在只支持单个代码。

  

首先,Instagram API端点“标签”需要OAuth身份验证。

这不完全正确,您只需要一个API密钥。只需register一个应用程序并将其添加到您的请求中。 例如:

https://api.instagram.com/v1/users/userIdYouWantToGetMediaFrom/media/recent?client_id=yourAPIKey

另请注意,用户名不是用户ID。您可以查找user-Id的here.

搜索多个关键字的解决方法是,如果您为每个标记启动一个请求并比较服务器上的结果。当然,这可能会降低您的网站速度,具体取决于您要比较的关键字数量。

答案 2 :(得分:6)

点击此处开始: http://instagram.com/developer/

然后为了按标签检索图片,请看这里: http://instagram.com/developer/endpoints/tags/

从Instagram获取代码不需要OAuth,因此您可以通过以下网址进行调用:

GET IMAGES https://api.instagram.com/v1/tags/{tag-name}/media/recent?access_token={TOKEN}

SEARCH https://api.instagram.com/v1/tags/search?q={tag-query}&access_token={TOKEN}

TAG INFO https://api.instagram.com/v1/tags/{tag-name}?access_token={TOKEN}