PHP を使用して Instagram から特定のハッシュ タグを持つすべての写真を取得したいと考えています。どうやってやるの?
3 に答える
まず、Instagram API エンドポイントの「タグ」には OAuth 認証が必要でした。
次の URL を使用して、特定のハッシュタグ (この場合は snowy) の結果を照会できます。
1 時間あたり 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"
}
}
}
ここで遊ぶことができます:
「認証」を OAuth 2 として使用する必要があり、Instagram 経由でサインインするよう求められます。「テンプレート」セクションの「タグ名」を再入力する必要があるかもしれないことを投稿してください。
ページネーション関連のすべてのデータは、応答の「pagination」パラメーターで使用でき、その「next_url」を使用して次の結果セットを照会します。
複数のタグを使用してコンテンツを検索することはまだできません。現在は単一のタグのみがサポートされています。
まず、Instagram API エンドポイントの「タグ」には OAuth 認証が必要でした。
これは正確ではありません。必要なのは API キーだけです。アプリケーションを登録してリクエストに追加するだけです。例:
https://api.instagram.com/v1/users/userIdYouWantToGetMediaFrom/media/recent?client_id=yourAPIKey
また、ユーザー名はユーザー ID ではないことに注意してください。ここでユーザー ID を検索できます。
複数のキーワードを検索する場合の回避策は、タグごとに 1 つのリクエストを開始し、サーバーで結果を比較することです。もちろん、比較するキーワードの量によっては、サイトの速度が低下する可能性があります.
開始するには、こちらをご覧ください: 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}