用curl命令行访问twitter的public timeline

文章参考:https://dev.twitter.com/discussions/14460


首先要有twitter帐号,去注册一个,登录

然后去下面的网址创建一个自己的app

https://dev.twitter.com/apps

创建完后,选择Detail tab,点击“Create my access token" 按钮。

然后再去OAuth Tool tab.

输入Request URL:

https://api.twitter.com/1.1/statuses/user_timeline.json


输入Query

screen_name=twitterapi


点击"See OAuth signature for this request"

然后就看到OAuth Signing Results,有推荐的curl命令行,

运行一下:(有些为了保密用...代替了)

curl --get 'https://api.twitter.com/1.1/statuses/user_timeline.json' --data 'screen_name=twitterapi' --header 'Authorization: OAuth oauth_consumer_key="...", oauth_nonce="...", oauth_signature="...", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1389625082", oauth_token="...", oauth_version="1.0"' --verbose

看到一堆信息输出,这里只展示片段:

_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":6253282,"id_str":"6253282","name":"Twitter API","screen_name":"twitterapi","location":"San Francisco, CA","description":"T\
he Real Twitter API. I tweet about API changes, service issues and happily answer questions about Twitter and our API. Don't get an answer? It's on my website.","url":"http:\/\/t.co\/78pYTvWfJd","entities":{"url"\
:{"urls":[{"url":"http:\/\/t.co\/78pYTvWfJd","expanded_url":"http:\/\/dev.twitter.com","display_url":"dev.twitter.com","indices":[0,22]}]},"description":{"urls":[]}},"protected":false,"followers_count":2013211,"f\
riends_count":44,"listed_count":12315,"created_at":"Wed May 23 06:01:13 +0000 2007","favourites_count":25,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":true,"statuses_\
count":3472,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/656927849\/miyt9dpj\
z77sc0w3d4vj.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/656927849\/miyt9dpjz77sc0w3d4vj.png","profile_background_tile":true,"profile_image_url":"http:\/\/pbs.tw\
img.com\/profile_images\/2284174872\/7df3h38zabcvjylnyfe3_normal.png","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/2284174872\/7df3h38zabcvjylnyfe3_normal.png","profile_banner_url":"https:\\
/\/pbs.twimg.com\/profile_banners\/6253282\/1347394302","profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_backg\
round_image":true,"default_profile":false,"* Connection #0 to host api.twitter.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):
default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false},"geo":null,"coordinates":null,"place":null,"contributors":null,"retweet_count":346,"favorite_count":121,"entities"\
:{"hashtags":[],"symbols":[],"urls":[{"url":"https:\/\/t.co\/r5MTaLVAWA","expanded_url":"https:\/\/dev.twitter.com\/blog\/test-accounts-user-ids-greater-32-bits","display_url":"dev.twitter.com\/blog\/test-acco\u2\
026","indices":[120,143]}],"user_mentions":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"lang":"en"}]

github上有一个脚本,非常方便:

https://github.com/gianu/latest_tweets

你可能感兴趣的:(用curl命令行访问twitter的public timeline)