这可以监视用户的新推文:
[value, position] = max (res_signal_example.nRx_raw_matrix_wout_noise, [], [1 2])
我的任务只是略有不同。我想阅读用户过去的所有推文。这是我的尝试:
position
输出为:
# https://github.com/inueni/birdy
from birdy.twitter import StreamClient
def stream_tweets_by2(user='foxnews'):
client = StreamClient(CONSUMER_KEY,
CONSUMER_SECRET,
ACCESS_TOKEN,
ACCESS_TOKEN_SECRET)
response = client.stream.statuses.filter.post(track=user)
for data in response.stream():
print(data)
健全性检查:
def get_user_timeline(screen_name='MiroslavVitkov'):
client = UserClient(CONSUMER_KEY,
CONSUMER_SECRET,
ACCESS_TOKEN,
ACCESS_TOKEN_SECRET)
# https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html
response = client.stream.statuses.user_timeline.get(screen_name=screen_name)
print('Oh, yeah!')
return response.data
相同的密钥,相同的秘密。一个提示是,将$ ./collect.py
Traceback (most recent call last):
File "./collect.py", line 135, in <module>
get_user_timeline()
File "./collect.py", line 87, in get_user_timeline
response = client.stream.statuses.user_timeline.get(screen_name=screen_name)
File "/home/vorac/.local/lib/python3.7/site-packages/birdy/twitter.py", line 81, in get
return self._client.request('GET', self._path, **params)
File "/home/vorac/.local/lib/python3.7/site-packages/birdy/twitter.py", line 167, in request
return self.handle_response(method, response)
File "/home/vorac/.local/lib/python3.7/site-packages/birdy/twitter.py", line 189, in handle_response
raise TwitterApiError('Unable to decode JSON response.', response=response, request_method=method)
birdy.twitter.TwitterApiError: Unable to decode JSON response. (GET https://stream.twitter.com/1.1/statuses/user_timeline.json?screen_name=MiroslavVitkov)
更改为$ twurl /1.1/statuses/user_timeline.json?screen_name=MiroslavVitkov
[{"created_at":"Wed Jan 16 17:03:38 +0000 2019","id":1085583367574351872,"id_str":"1085583367574351872","text":"@gabberetta \u0432\u0435\u0447\u0435 \u0438\u043c\u0430\u043c \u0442\u0443\u0438\u0442\u0435\u0440 \u0430\u043a\u0430\u0443\u043d\u0442! \u0418 \u0434\u043e \u043d\u044f\u043a\u043e\u043b\u043a\u043e \u0434\u043d\u0438 \u0449\u0435 \u043c\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u0434\u0430 \u0441\u0432\u0430\u043b\u044f\u043c \u043f\u043e 5 400 000 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u043d\u0438 \u0442\u0443\u0438\u0439\u0442\u0430 \u043d\u0430 \u0434\u0435\u043d!","truncated":false,"entities":{"hashtags":[],"symbols":[],"user_mentions":[{"screen_name":"gabberetta","name":"\u0411\u0438\u0441\u0435\u0440\u0430 \u0420\u0443\u0436\u0438\u043d\u0430","id":37703455,"id_str":"37703455","indices":[0,11]}],"urls":[]},"source":"\u003ca href=\"http:\/\/twitter.com\" rel=\"nofollow\"\u003eTwitter Web Client\u003c\/a\u003e","in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":37703455,"in_reply_to_user_id_str":"37703455","in_reply_to_screen_name":"gabberetta","user":{"id":1085578386368536576,"id_str":"1085578386368536576","name":"MiroslavVitkov","screen_name":"MiroslavVitkov","location":"","description":"","url":null,"entities":{"description":{"urls":[]}},"protected":false,"followers_count":0,"friends_count":0,"listed_count":0,"created_at":"Wed Jan 16 16:43:51 +0000 2019","favourites_count":0,"utc_offset":null,"time_zone":null,"geo_enabled":false,"verified":false,"statuses_count":1,"lang":"en","contributors_enabled":false,"is_translator":false,"is_translation_enabled":false,"profile_background_color":"F5F8FA","profile_background_image_url":null,"profile_background_image_url_https":null,"profile_background_tile":false,"profile_image_url":"http:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_normal.png","profile_image_url_https":"https:\/\/abs.twimg.com\/sticky\/default_profile_images\/default_profile_normal.png","profile_link_color":"1DA1F2","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"has_extended_profile":false,"default_profile":true,"default_profile_image":true,"following":false,"follow_request_sent":false,"notifications":false,"translator_type":"none"},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":0,"favorited":false,"retweeted":false,"
会以相同的方式失败。请告知。
答案 0 :(得分:1)
端点:
response = client.stream.statuses.filter.post(track=user)
是指流式API:https://developer.twitter.com/en/docs/tweets/filter-realtime/api-reference/post-statuses-filter.html
用户时间轴指的是其余的API:https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html,因此尝试像您一样使用流api将无法正常工作:
response = client.stream.statuses.user_timeline.get(screen_name=screen_name)
所以尝试一下:
response = client.api.statuses.user_timeline.get(screen_name=screen_name)