python – 如何串流叽叽叽t witter y y y?

python – 如何串流叽叽叽t witter y y y?,第1张

概述我目前正在使用以下代码,这会得到推文,然后将其传递给处理的函数.这不是实时的. auth = tweepy.OAuthHandler(consumer_key, consumer_secret)auth.set_access_token(access_token, access_token_secret)api = tweepy.API(auth)mentions = api.mention 我目前正在使用以下代码,这会得到推文,然后将其传递给处理的函数.这不是实时的.
auth = tweepy.OAuthHandler(consumer_key,consumer_secret)auth.set_access_token(access_token,access_token_secret)API = tweepy.API(auth)mentions = API.mentions_timeline(count=1)for mention in mentions:   processtext()

我也看过流媒体播放器,但我还没有找到一个提供流媒体的方法.

解决方法 您可以使用 Streaming API过滤包含@mentions的推文.当您使用跟踪参数过滤流时,请按照您感兴趣的用户名过滤您的跟踪参数中的用户名,如下所示:
stream.filter(track=['twitterapi'])

这将返回您所有包含字符串“twitterapi”的推文,包括@mentions(即“@twitterapi”).请参阅Twitter Streaming API track parameter了解如何工作.然后,您可以使用结果JsON只采取实际上对您感兴趣的用户进行@的结果的JsON.结果JsON如下所示:

{"retweet_count":0,"text":"Man I like me some @twitterapi","entitIEs":{"urls":[],"hashTags":[],"user_mentions":[{"indices":[19,30],"name":"Twitter API","ID":6253282,"screen_name":"twitterapi","ID_str":"6253282"}]},"retweeted":false,"in_reply_to_status_ID_str":null,"place":null,"in_reply_to_user_ID_str":null,"coordinates":null,"source":"web","in_reply_to_screen_name":null,"in_reply_to_user_ID":null,"in_reply_to_status_ID":null,"favorited":false,"contributors":null,"geo":null,"truncated":false,"created_at":"Wed Feb 29 19:42:02 +0000 2012","user":{"is_translator":false,"follow_request_sent":null,"statuses_count":142,"profile_background_color":"C0DEED","default_profile":false,"lang":"en","notifications":null,"profile_background_tile":true,"location":"","profile_sIDebar_fill_color":"ffffff","followers_count":8,"profile_image_url":"http:\/\/a1.twimg.com\/profile_images\/1540298033\/phatkicks_normal.jpg","contributors_enabled":false,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/365782739\/doof.jpg","description":"I am just a testing account,following me probably won't gain you very much","following":null,"profile_sIDebar_border_color":"C0DEED","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1540298033\/phatkicks_normal.jpg","default_profile_image":false,"show_all_inline_media":false,"verifIEd":false,"profile_use_background_image":true,"favourites_count":1,"frIEnds_count":5,"profile_text_color":"333333","protected":false,"profile_background_image_url":"http:\/\/a3.twimg.com\/profile_background_images\/365782739\/doof.jpg","time_zone":"Pacific Time (US & Canada)","created_at":"Fri Sep 09 16:13:20 +0000 2011","name":"fakekurrik","geo_enabled":true,"profile_link_color":"0084B4","url":"http:\/\/blog.roomanna.com","ID":370773112,"ID_str":"370773112","Listed_count":0,"utc_offset":-28800,"screen_name":"fakekurrik"},"ID":174942523154894848,"ID_str":"174942523154894848"}

这很糟糕,但是如果您查看“实体”对象,则会看到“user_mentions”:

"user_mentions":[{"indices":[19,"ID_str":"6253282"}]

然后,在“screen_name”下,您会看到“twitterapi”,显示用户@twitterapi是@ referenced.

总结

以上是内存溢出为你收集整理的python – 如何串流叽叽叽t witter y y y?全部内容,希望文章能够帮你解决python – 如何串流叽叽叽t witter y y y?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1206979.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存