gpt4 book ai didi

Python - Tweepy,检索created_at

转载 作者:行者123 更新时间:2023-11-30 23:02:45 25 4
gpt4 key购买 nike

我正在尝试检索推文及其创建日期。这是我的代码到目前为止的样子:

import tweepy
import json
import urllib
import sys
import datetime

from tweepy import OAuthHandler

user = "billgates"
count = 1

def twitter_fetch(screen_name = user,maxnumtweets=count):

consumer_token = 'INSERT CONSUMER TOKEN'
consumer_secret = 'INSERT CONSUMER SECRET'
access_token = 'INSERT ACCESS TOKEN'
access_secret = 'INSERT ACCESS SECRET'

auth = tweepy.OAuthHandler(consumer_token,consumer_secret)
auth.set_access_token(access_token,access_secret)

api = tweepy.API(auth)

for status in tweepy.Cursor(api.user_timeline,id=screen_name).items(count):
print status.text+'\n'

if __name__ == '__main__':
twitter_fetch(user,count)

我知道我可能需要使用“created_at”来调用日期,但我不确定将其放在哪里才能检索它。我怎样才能做到这一点?

最佳答案

Wander Nauta said ,更改行:

for status in tweepy.Cursor(api.user_timeline,id=screen_name).items(count):
print status.text + '\n'

至:

for status in tweepy.Cursor(api.user_timeline,id=screen_name).items(count):
print status.text + ' ' + str(status.created_at) + '\n'

应打印出推文以及推文创建的时间和日期。

关于Python - Tweepy,检索created_at,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34358059/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com