2 回答
TA贡献1789条经验 获得超10个赞
我想到了!我知道循环被用于某些事情......
我将所有内容从a = len(tweetstowget.download(url)移到for tweet in tweets:循环中,并删除了for i in id_list:循环。
感谢 tdelany,这个程序现在可以运行了!感谢大家!
如果有人想要,这是新代码:
#!/usr/bin/env python
# encoding: utf-8
import tweepy #https://github.com/tweepy/tweepy
import wget
#Twitter API credentials
consumer_key = "nice try :)"
consumer_secret = "nice try :)"
access_key = "nice try :)"
access_secret = "my, this joke is getting really redundant"
def get_all_tweets():
#authorize twitter, initialize tweepy
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
id_list = [1234567890, 0987654321]
# Hey StackOverflow, these are example ID's. They won't work as they're not real twitter ID's, so if you're gonna run this yourself, you'll want to find some twitter IDs on your own
tweets = []
tweets.extend(api.statuses_lookup(id_=id_list, include_entities=True))
for tweet in tweets:
a = len(tweets)
print(tweet.entities['media'][0]['media_url'])
url = tweet.entities['media'][0]['media_url']
wget.download(url)
get_all_tweets()
TA贡献1871条经验 获得超13个赞
我看到的一件奇怪的事情是,我在外循环中声明的变量在 on 之后从未使用过。你的代码不应该是
tweets.extend(api.statuses_lookup(id_=i, include_entities=True))
而不是你写的 id_=id_list ?
添加回答
举报