25

我想使用 PHP 从 Instagram 获取所有带有特定哈希标签的图片。我怎样才能做到这一点?

4

3 回答 3

15

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

您可以使用以下 url 查询特定主题标签(在本例中为下雪)的结果

它的速率限制为每小时 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”来查询下一组结果。

于 2013-06-05T07:59:50.027 回答
11

目前尚无法使用多个标签搜索内容,目前仅支持单个标签。

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

这并不完全正确,您只需要一个 API-Key。只需注册一个应用程序并将其添加到您的请求中。例子:

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

另请注意,用户名不是用户 ID。您可以在此处查找用户 ID

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

于 2014-01-22T14:38:44.227 回答
6

看看这里为了开始:http: //instagram.com/developer/

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

从 Instagram 获取标签不需要 OAuth,因此您可以通过以下 URL 进行调用:

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}

于 2012-11-01T14:22:31.013 回答