简体   繁体   English

从不带json对象的tweet ID获取Twitter用户ID

[英]Getting twitter user id from tweet id without json object

Currently I am working on twitter data. 目前,我正在处理Twitter数据。 I need to fetch twitter data with the tweet id and user id of the tweet. 我需要获取带有推文ID推文 用户ID的Twitter数据。 Unfortunately, I am able to fetch the tweet with tweet id only. 不幸的是,我只能使用推特ID来获取该推 But along with that I want to get the user id too. 但是与此同时,我也想获取用户ID I am fetching the tweets by giving the query of the search type. 我通过提供搜索类型的查询来获取这些推文。 By working with individual tweet id I am able to get the username and from that username I can get the user id . 通过使用单独的tweet ID,我可以获取用户名,并从该用户名中获取用户ID But this manual work for each tweet is too lenghty. 但是,每条推文的手动操作都太冗长。 Can't there be a way to get directly the user id from the tweet id . 无法从tweet id直接获取用户ID的方法。

I am using python with tweepy library. 我在tweepy库中使用python。

code for search with tweepy. tweepy搜索代码。 public_tweets = api.search(q="TheGhantas", lang ="en", count = 200) public_tweets.id_str is returning me the tweet id and this is helping me to get the tweet username. public_tweets = api.search(q="TheGhantas", lang ="en", count = 200) public_tweets.id_str我返回了tweet ID ,这有助于我获取tweet用户名。 And from that username, I am getting the user id . 然后从该用户名获取用户ID Can there be a simple way to get directly the user id from tweet ids if I have a file with tweet ids ? 如果我有一个包含推文ID的文件,是否有一种简单的方法可以直接从推文ID获取用户 ID

Yes, it is very simple. 是的,这很简单。

You look up the Tweet using statuses/show . 您可以使用statuses/show查找Tweet。 That will return the Tweet object as JSON. 那将把Tweet对象返回为JSON。

Inside that JSON you will find the user object. 在该JSON中,您将找到用户对象。

Here is a shortened example: 这是一个简短的示例:

{
  "created_at": "Wed Jun 06 20:07:10 +0000 2012",
  "id_str": "210462857140252672",
  "text": "Along with our new #Twitterbird, we've also updated our Display Guidelines ^JC",
  "id": 210462857140252672,
  "user": {
    "name": "Twitter API",
    "id_str": "6253282",
    "statuses_count": 3333,
    "screen_name": "twitterapi"
  },
}

Depending on how you're getting the JSON, it's as simple as going tweet->user->screen_name 取决于您获取JSON的方式,就像去tweet->user->screen_name一样简单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM