ストリーミングAPIに新機能

水曜日, 2014年8月20日水曜日

この記事はAdding new features to Streaming APIの和訳です。

REST APIとストリーミングAPIの一貫性のため、ストリーミングAPIに新機能を追加する予定です。JSONに追加される項目とその例は以下をご参照ください。

タイムスタンプ:ストリーミングAPIで流れるどの通知にも、ミリ秒単位のタイムスタンプが入ります。タイムスタンプは通知の順序付けに役に立つはずです。

ミュート通知:ユーザーストリームやサイトストリームでは、ユーザーがミュートしたアカウントのツイートをすぐ排除するのに役に立ちます。ミュートやミュート解除の通知はミュートをした本人だけに送られます。

マルチプル・メディア・エンティティ:ツイートに複数の画像が入っている場合、ストリーミングAPIでも全ての画像の情報がJSONに入るようになります。

詳しいJSONの例

タイムスタンプ

“timestamp_ms”という項目が通知に追加される。値がイベントが起きた時の1970/01/01 00:00:00 UTCからのミリ秒数です。数字ではありますが、文字列として表されます。

{
  "event_name": {
    ...
    "timestamp_ms": "1403907978000"
  }
}

上記の”event_name”が下記のどれかになります。

user_protect
user_unprotect
user_suspend
user_unsuspend
user_delete
user_undelete
user_withheld
status_withheld
delete
scrub_geo
limit
warning

上記の通知だけではなく、各ツイートにも“timestamp_ms”項目が入ります。

https://dev.twitter.com/docs/platform-objects/tweets

ミュート・ミュート解除

ユーザーが他人のアカウントをミュート、またはミュート解除、をすると、“mute”と“unmute”という新しい通知がユーザーストリームとサイトストリームで流れます。その通知に入っている“target”項目にミュートまたはミュート解除されたアカウントの情報が入ります。ミュートをした人(source)だけに送られます。文字列として表されます。

{
   "event": "unmute",
   "source": { ... },
   "target": { ... },
   "created_at": "Mon Apr 24 21:24:59 +0000 2014"
}
{
   "event": "mute",
   "source": { ... },
   "target": { ... },
   "created_at": "Mon Apr 24 21:28:59 +0000 2014"
}

“target”に入る情報の一例が以下に掲載されています。

"target": {
  "muting": false
  "id": 2467267646,
  "id_str": "2467267646",
  "name": "Bharati Prasad",
  "screen_name": "prasadbharati2",
  "location": null,
  "url": null,
  "description": null,
  "protected": false,
  "followers_count": 1,
  "friends_count": 10,
  "listed_count": 0,
  "created_at": "Mon Apr 28 05:44:22 +0000 2014",
  "favourites_count": 0,
  "utc_offset": null,
  "time_zone": null,
  "geo_enabled": false,
  "verified": false,
  "statuses_count": 7,
  "lang": "en",
  "contributors_enabled": false,
  "is_translator": false,
  "is_translation_enabled": false,
  "profile_background_color": "C0DEED",
  "profile_background_image_url": "http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png",
  "profile_background_image_url_https": "https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png",
  "profile_background_tile": false,
  "profile_image_url": "http:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_4_normal.png",
  "profile_image_url_https": "https:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_4_normal.png",
  "profile_link_color": "0084B4",
  "profile_sidebar_border_color": "C0DEED",
  "profile_sidebar_fill_color": "DDEEF6",
  "profile_text_color": "333333",
  "profile_use_background_image": true,
  "default_profile": true,
  "default_profile_image": true,
  "following": true,
  "follow_request_sent": false,
  "notifications": false
}
マルチプル・メディア・エンティティ

複数の画像の入っているツイートのすべての画像の情報が“extended_entities”項目に入ります。その中に、下記のJSONの “pic.twitter.com/fxmuQN9JL9” のように、同じURLに結びつく画像は最大4つです。“extended_entites”の“indices”で、ツイートに入っているURLの位置の範囲が指定されます。

“entities”と異なり、“extended_entites”には複数のエンティティが同じURLに結びついていることがあるので、ご注意ください。ひとつのURLに結びついている複数のエンティティの“indices”は同じものです。“entities”には、各エンティティの“indices”が被らない範囲を指定します。

"entities": {
  "hashtags": [],
  "media": [
    {
      "display_url": "pic.twitter.com/fxmuQN9JL9",
      "expanded_url": "http://twitter.com/FLOTUS/status/449660889793581056/photo/1",
      "id": 449660809380380673,
      "id_str": "449660809380380673",
      "indices": [
        121,
        143
      ],
      "media_url": "http://pbs.twimg.com/media/Bj2EH6yIQAEYvxu.jpg",
      "media_url_https": "https://pbs.twimg.com/media/Bj2EH6yIQAEYvxu.jpg",
      "sizes": {
        "large": {
          "h": 426,
          "resize": "fit",
          "w": 640
        },
        "medium": {
          "h": 399,
          "resize": "fit",
          "w": 600
        },
        "small": {
          "h": 226,
          "resize": "fit",
          "w": 340
        },
        "thumb": {
          "h": 150,
          "resize": "crop",
          "w": 150
        }
      },
      "type": "photo",
      "url": "http://t.co/fxmuQN9JL9"
    }
  ],
  "symbols": [],
  "urls": [],
  "user_mentions": []
},
"extended_entities": {
  "media": [
    {
      "display_url": "pic.twitter.com/fxmuQN9JL9",
      "expanded_url": "http://twitter.com/FLOTUS/status/449660889793581056/photo/1",
      "id": 449660809380380673,
      "id_str": "449660809380380673",
      "indices": [
        121,
        143
      ],
      "media_url": "http://pbs.twimg.com/media/Bj2EH6yIQAEYvxu.jpg",
      "media_url_https": "https://pbs.twimg.com/media/Bj2EH6yIQAEYvxu.jpg",
      "sizes": {
        "large": {
          "h": 426,
          "resize": "fit",
          "w": 640
        },
        "medium": {
          "h": 399,
          "resize": "fit",
          "w": 600
        },
        "small": {
          "h": 226,
          "resize": "fit",
          "w": 340
        },
        "thumb": {
          "h": 150,
          "resize": "crop",
          "w": 150
        }
      },
      "type": "photo",
      "url": "http://t.co/fxmuQN9JL9"
    },
    {
      "display_url": "pic.twitter.com/fxmuQN9JL9",
      "expanded_url": "http://twitter.com/FLOTUS/status/449660889793581056/photo/1",
      "id": 449660806754738177,
      "id_str": "449660806754738177",
      "indices": [
        121,
        143
      ],
      "media_url": "http://pbs.twimg.com/media/Bj2EHxAIIAE8dtg.jpg",
      "media_url_https": "https://pbs.twimg.com/media/Bj2EHxAIIAE8dtg.jpg",
      "sizes": {
        "large": {
          "h": 426,
          "resize": "fit",
          "w": 640
        },
        "medium": {
          "h": 399,
          "resize": "fit",
          "w": 600
        },
        "small": {
          "h": 226,
          "resize": "fit",
          "w": 340
        },
        "thumb": {
          "h": 150,
          "resize": "crop",
          "w": 150
        }
      },
      "type": "photo",
      "url": "http://t.co/fxmuQN9JL9"
    },
    {
      "display_url": "pic.twitter.com/fxmuQN9JL9",
      "expanded_url": "http://twitter.com/FLOTUS/status/449660889793581056/photo/1",
      "id": 449660808537333761,
      "id_str": "449660808537333761",
      "indices": [
        121,
        143
      ],
      "media_url": "http://pbs.twimg.com/media/Bj2EH3pIYAE4LQn.jpg",
      "media_url_https": "https://pbs.twimg.com/media/Bj2EH3pIYAE4LQn.jpg",
      "sizes": {
        "large": {
          "h": 427,
          "resize": "fit",
          "w": 640
        },
        "medium": {
          "h": 400,
          "resize": "fit",
          "w": 600
        },
        "small": {
          "h": 227,
          "resize": "fit",
          "w": 340
        },
        "thumb": {
          "h": 150,
          "resize": "crop",
          "w": 150
        }
      },
      "type": "photo",
      "url": "http://t.co/fxmuQN9JL9"
    },
    {
      "display_url": "pic.twitter.com/fxmuQN9JL9",
      "expanded_url": "http://twitter.com/FLOTUS/status/449660889793581056/photo/1",
      "id": 449660877097406464,
      "id_str": "449660877097406464",
      "indices": [
        121,
        143
      ],
      "media_url": "http://pbs.twimg.com/media/Bj2EL3DIEAAzGAX.jpg",
      "media_url_https": "https://pbs.twimg.com/media/Bj2EL3DIEAAzGAX.jpg",
      "sizes": {
        "large": {
          "h": 426,
          "resize": "fit",
          "w": 640
        },
        "medium": {
          "h": 399,
          "resize": "fit",
          "w": 600
        },
        "small": {
          "h": 226,
          "resize": "fit",
          "w": 340
        },
        "thumb": {
          "h": 150,
          "resize": "crop",
          "w": 150
        }
      },
      "type": "photo",
      "url": "http://t.co/fxmuQN9JL9"
    }
  ]
},

上記のJSONで表されているツイート: