如何使用 tweepy 获取屏幕名称而不是用户 ID [英] How to get screen name instead of user ID with tweepy

查看:52
本文介绍了如何使用 tweepy 获取屏幕名称而不是用户 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将 Twitter 提要中的推文打印到 CSV 文件中,并希望让 CSV 文件显示用户名而不是用户 ID.

I'm printing out the tweets from my twitter feed to a CSV and want to get the CSV to show the username instead of the user ID.

我的代码使用 tweepy.

My code uses tweepy.

outtweets.append([tweet.id_str, tweet.created_at, tweet.text.encode("utf-8")])

这是我在循环中用来获取用户 ID 的内容.我将如何获取屏幕名称?

This is what I use in my loop to get the user ID. How would I go about to get the screen name instead?

推荐答案

参见 https://dev.twitter.com/overview/api/tweets Tweet 对象和 https://dev.twitter.com/overview/api/users 用户对象.

See https://dev.twitter.com/overview/api/tweets Tweet object and https://dev.twitter.com/overview/api/users User object.

这将表明您需要使用:

tweet.user.name

访问用户名

这篇关于如何使用 tweepy 获取屏幕名称而不是用户 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆