推特流 API java 按日期搜索
twitter streaming API java search by date
我做了一个 twitter 申请,得到了 application settings
和 access token
。
我可以使用官方 java 库 hbc-core
和 hbc-twitter4j
或 twitter4j.org 的 twitter4j
.
- 不确定如何验证和启动流(functions/instances 使用)
- 要查询什么function/instance
例如,我想在 2016-02-13(日期是请求后一周内)。我想 return tweet id
、user id
、number of retweets
和 number of replies
我建议使用 twitters/hbc quickstart. You need to have maven 安装。然后您可以 git install
快速入门和 运行 示例应用程序:
mvn install && mvn exec:java -pl hbc-example -Dconsumer.key=XYZ -Dconsumer.secret=SECRET -Daccess.token=ABC -Daccess.token.secret=ABCSECRET
并将您的凭据放在 =
后的引号中。如果您查看此源代码,您可以将此代码用作游乐场,以了解如何将此客户端与 Twitter API 一起使用。然后只需查看代码 examples and pick what you need to achieve the functionality you're looking for and combine that with the endpoints you would need from twitter, specifically these 以搜索主题标签并获得 json 就像这样
{
"created_at": "Mon Feb 13 08:47:02 +0000 2017",
"id": 831062112478822400,
"id_str": "831062112478822400",
"text": "You've been doing #DataReporting all wrong. This is how you create powerful insights with #data:\u2026 https:\/\/t.co\/w5rHjKMGza",
"display_text_range": [0, 140],
"source": "\u003ca href=\"http:\/\/bufferapp.com\" rel=\"nofollow\"\u003eBuffer\u003c\/a\u003e",
"truncated": true,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 2953426294,
"id_str": "2953426294",
"name": "Developing Edge",
"screen_name": "ptdevedge",
"location": "United Kingdom",
"url": "http:\/\/developingedge.com\/",
"description": null,
"protected": false,
"verified": false,
"followers_count": 455,
"friends_count": 225,
"listed_count": 132,
"favourites_count": 44,
"statuses_count": 854,
"created_at": "Wed Dec 31 16:42:36 +0000 2014",
"utc_offset": 0,
"time_zone": "London",
"geo_enabled": false,
"lang": "en-gb",
"contributors_enabled": false,
"is_translator": false,
"profile_background_color": "000000",
"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_link_color": "C56200",
"profile_sidebar_border_color": "000000",
"profile_sidebar_fill_color": "000000",
"profile_text_color": "000000",
"profile_use_background_image": false,
"profile_image_url": "http:\/\/pbs.twimg.com\/profile_images\/713668391710638080\/R1-V_Zvh_normal.jpg",
"profile_image_url_https": "https:\/\/pbs.twimg.com\/profile_images\/713668391710638080\/R1-V_Zvh_normal.jpg",
"profile_banner_url": "https:\/\/pbs.twimg.com\/profile_banners\/2953426294\/1450889452",
"default_profile": false,
"default_profile_image": false,
"following": null,
"follow_request_sent": null,
"notifications": null
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"extended_tweet": {
"full_text": "You've been doing #DataReporting all wrong. This is how you create powerful insights with #data: https:\/\/t.co\/zSXxWLy0fY https:\/\/t.co\/BcbvZdewKb",
"display_text_range": [0, 120],
"entities": {
"hashtags": [{
"text": "DataReporting",
"indices": [18, 32]
}, {
"text": "data",
"indices": [90, 95]
}],
"urls": [{
"url": "https:\/\/t.co\/zSXxWLy0fY",
"expanded_url": "http:\/\/bit.ly\/powerful-data-insights",
"display_url": "bit.ly\/powerful-data-\u2026",
"indices": [97, 120]
}],
"user_mentions": [],
"symbols": [],
"media": [{
"id": 831062108943024131,
"id_str": "831062108943024131",
"indices": [121, 144],
"media_url": "http:\/\/pbs.twimg.com\/media\/C4iGlb3WAAMAwAL.jpg",
"media_url_https": "https:\/\/pbs.twimg.com\/media\/C4iGlb3WAAMAwAL.jpg",
"url": "https:\/\/t.co\/BcbvZdewKb",
"display_url": "pic.twitter.com\/BcbvZdewKb",
"expanded_url": "https:\/\/twitter.com\/ptdevedge\/status\/831062112478822400\/photo\/1",
"type": "photo",
"sizes": {
"medium": {
"w": 1024,
"h": 768,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1024,
"h": 768,
"resize": "fit"
},
"small": {
"w": 680,
"h": 510,
"resize": "fit"
}
}
}]
},
"extended_entities": {
"media": [{
"id": 831062108943024131,
"id_str": "831062108943024131",
"indices": [121, 144],
"media_url": "http:\/\/pbs.twimg.com\/media\/C4iGlb3WAAMAwAL.jpg",
"media_url_https": "https:\/\/pbs.twimg.com\/media\/C4iGlb3WAAMAwAL.jpg",
"url": "https:\/\/t.co\/BcbvZdewKb",
"display_url": "pic.twitter.com\/BcbvZdewKb",
"expanded_url": "https:\/\/twitter.com\/ptdevedge\/status\/831062112478822400\/photo\/1",
"type": "photo",
"sizes": {
"medium": {
"w": 1024,
"h": 768,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1024,
"h": 768,
"resize": "fit"
},
"small": {
"w": 680,
"h": 510,
"resize": "fit"
}
}
}]
}
},
"retweet_count": 0,
"favorite_count": 0,
"entities": {
"hashtags": [{
"text": "DataReporting",
"indices": [18, 32]
}, {
"text": "data",
"indices": [90, 95]
}],
"urls": [{
"url": "https:\/\/t.co\/w5rHjKMGza",
"expanded_url": "https:\/\/twitter.com\/i\/web\/status\/831062112478822400",
"display_url": "twitter.com\/i\/web\/status\/8\u2026",
"indices": [98, 121]
}],
"user_mentions": [],
"symbols": []
},
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"filter_level": "low",
"lang": "en",
"timestamp_ms": "1486975622659"
}
我做了一个 twitter 申请,得到了 application settings
和 access token
。
我可以使用官方 java 库 hbc-core
和 hbc-twitter4j
或 twitter4j.org 的 twitter4j
.
- 不确定如何验证和启动流(functions/instances 使用)
- 要查询什么function/instance
例如,我想在 2016-02-13(日期是请求后一周内)。我想 return tweet id
、user id
、number of retweets
和 number of replies
我建议使用 twitters/hbc quickstart. You need to have maven 安装。然后您可以 git install
快速入门和 运行 示例应用程序:
mvn install && mvn exec:java -pl hbc-example -Dconsumer.key=XYZ -Dconsumer.secret=SECRET -Daccess.token=ABC -Daccess.token.secret=ABCSECRET
并将您的凭据放在 =
后的引号中。如果您查看此源代码,您可以将此代码用作游乐场,以了解如何将此客户端与 Twitter API 一起使用。然后只需查看代码 examples and pick what you need to achieve the functionality you're looking for and combine that with the endpoints you would need from twitter, specifically these 以搜索主题标签并获得 json 就像这样
{
"created_at": "Mon Feb 13 08:47:02 +0000 2017",
"id": 831062112478822400,
"id_str": "831062112478822400",
"text": "You've been doing #DataReporting all wrong. This is how you create powerful insights with #data:\u2026 https:\/\/t.co\/w5rHjKMGza",
"display_text_range": [0, 140],
"source": "\u003ca href=\"http:\/\/bufferapp.com\" rel=\"nofollow\"\u003eBuffer\u003c\/a\u003e",
"truncated": true,
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 2953426294,
"id_str": "2953426294",
"name": "Developing Edge",
"screen_name": "ptdevedge",
"location": "United Kingdom",
"url": "http:\/\/developingedge.com\/",
"description": null,
"protected": false,
"verified": false,
"followers_count": 455,
"friends_count": 225,
"listed_count": 132,
"favourites_count": 44,
"statuses_count": 854,
"created_at": "Wed Dec 31 16:42:36 +0000 2014",
"utc_offset": 0,
"time_zone": "London",
"geo_enabled": false,
"lang": "en-gb",
"contributors_enabled": false,
"is_translator": false,
"profile_background_color": "000000",
"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_link_color": "C56200",
"profile_sidebar_border_color": "000000",
"profile_sidebar_fill_color": "000000",
"profile_text_color": "000000",
"profile_use_background_image": false,
"profile_image_url": "http:\/\/pbs.twimg.com\/profile_images\/713668391710638080\/R1-V_Zvh_normal.jpg",
"profile_image_url_https": "https:\/\/pbs.twimg.com\/profile_images\/713668391710638080\/R1-V_Zvh_normal.jpg",
"profile_banner_url": "https:\/\/pbs.twimg.com\/profile_banners\/2953426294\/1450889452",
"default_profile": false,
"default_profile_image": false,
"following": null,
"follow_request_sent": null,
"notifications": null
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"extended_tweet": {
"full_text": "You've been doing #DataReporting all wrong. This is how you create powerful insights with #data: https:\/\/t.co\/zSXxWLy0fY https:\/\/t.co\/BcbvZdewKb",
"display_text_range": [0, 120],
"entities": {
"hashtags": [{
"text": "DataReporting",
"indices": [18, 32]
}, {
"text": "data",
"indices": [90, 95]
}],
"urls": [{
"url": "https:\/\/t.co\/zSXxWLy0fY",
"expanded_url": "http:\/\/bit.ly\/powerful-data-insights",
"display_url": "bit.ly\/powerful-data-\u2026",
"indices": [97, 120]
}],
"user_mentions": [],
"symbols": [],
"media": [{
"id": 831062108943024131,
"id_str": "831062108943024131",
"indices": [121, 144],
"media_url": "http:\/\/pbs.twimg.com\/media\/C4iGlb3WAAMAwAL.jpg",
"media_url_https": "https:\/\/pbs.twimg.com\/media\/C4iGlb3WAAMAwAL.jpg",
"url": "https:\/\/t.co\/BcbvZdewKb",
"display_url": "pic.twitter.com\/BcbvZdewKb",
"expanded_url": "https:\/\/twitter.com\/ptdevedge\/status\/831062112478822400\/photo\/1",
"type": "photo",
"sizes": {
"medium": {
"w": 1024,
"h": 768,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1024,
"h": 768,
"resize": "fit"
},
"small": {
"w": 680,
"h": 510,
"resize": "fit"
}
}
}]
},
"extended_entities": {
"media": [{
"id": 831062108943024131,
"id_str": "831062108943024131",
"indices": [121, 144],
"media_url": "http:\/\/pbs.twimg.com\/media\/C4iGlb3WAAMAwAL.jpg",
"media_url_https": "https:\/\/pbs.twimg.com\/media\/C4iGlb3WAAMAwAL.jpg",
"url": "https:\/\/t.co\/BcbvZdewKb",
"display_url": "pic.twitter.com\/BcbvZdewKb",
"expanded_url": "https:\/\/twitter.com\/ptdevedge\/status\/831062112478822400\/photo\/1",
"type": "photo",
"sizes": {
"medium": {
"w": 1024,
"h": 768,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1024,
"h": 768,
"resize": "fit"
},
"small": {
"w": 680,
"h": 510,
"resize": "fit"
}
}
}]
}
},
"retweet_count": 0,
"favorite_count": 0,
"entities": {
"hashtags": [{
"text": "DataReporting",
"indices": [18, 32]
}, {
"text": "data",
"indices": [90, 95]
}],
"urls": [{
"url": "https:\/\/t.co\/w5rHjKMGza",
"expanded_url": "https:\/\/twitter.com\/i\/web\/status\/831062112478822400",
"display_url": "twitter.com\/i\/web\/status\/8\u2026",
"indices": [98, 121]
}],
"user_mentions": [],
"symbols": []
},
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"filter_level": "low",
"lang": "en",
"timestamp_ms": "1486975622659"
}