全部转发

2024-09-28 23:17:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Tweepy和Python访问Twitter API。在

我想知道下面的问题是常见的还是只发生在我身上。在

我正在存储一些tweet。 转发的内容存储在这个fortmat中:

RT @User [text of the tweet]

我在这里注意到,即使用户使用“Retweet”按钮转发文本,文本总是以相同的格式存储(RT @User [text of the tweet]),当然,当Twitter API添加“RT @user”时,整个文本可以超过140个字符,因此它被存储,但不是完整的长度。在

如果问题不是一个常见的bug,那么对于那些使用Tweepy的用户来说,这个bug是来自它还是来自Twitter API?在


Tags: ofthetext用户文本api内容twitter
2条回答

这不是一个错误,而是一个正常的行为。要为截断字段引用the tweeter documentation,请执行以下操作:

Indicates whether the value of the text parameter was truncated, for example, as a result of a retweet exceeding the 140 character Tweet length. Truncated text will end in ellipsis, like this ...

[...]

Note that while native retweets may have their toplevel text property shortened, the original text will be available under the retweeted_status object and the truncated parameter will be set to the value of the original status (in most cases, false).

转发是一种特殊类型的tweet,它有一个称为“retweeted_status”的额外节点。 原始tweet的原始、未更改的tweet文本处于retweated_状态的文本字段中,而不像传统tweets那样位于最顶端的文本字段。在

试着跟着

import tweepy
import urllib2
import json
consumer_key='#'
consumer_secret='#'
access_token_key='#'
access_token_secret='#'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token_key, access_token_secret)
api = tweepy.API(auth)

public_tweets = api.user_timeline(screen_name="@HandleHere",count=25,page=1,include_rts=True)
all_items=[]
[all_items.append(i) for i in public_tweets]

for i in all_items:
    try:
        if i.retweeted_status:
            print i.retweeted_status.text
    except:
        pass

它将打印完整的转发推文。在

相关问题 更多 >