我有一个要使用tweepy下载的tweet ID列表,我在代码列表中包含了其中的一个样本,但所有这些我都出错了
我用实际的令牌和密钥替换了令牌和密钥,并尝试将tweet ID用作字符串和int,但都失败了,我总是收到“无数据可用于指定ID”错误
import tweepy
def download_tweets():
CONSUMER_KEY = "consumer key"
CONSUMER_SECRET = "consumer secret"
OAUTH_TOKEN = "auth token"
OAUTH_TOKEN_SECRET = "auth token secret"
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
api = tweepy.API(auth)
tweets_IDs = [434828570574479360, 434828682352672768, 434828730394230784, 434828787793276928, 434828917174992896, 434829014013067265, 434829430746537985, 434829430746537985, 434829552742068224]
for id in tweets_IDs:
tweet = api.get_status(tweet_id)
print(tweet)
错误: 引发TweepError(error_msg,resp,api_code = api_error_code) tweepy.error.TweepError:[{'code':8,8,'message':'无可用数据用于指定的ID。'}]
答案 0 :(得分:0)
除了两个ID外,所有ID现在都无效。这可能意味着它们从来都不是Tweet ID,它们是现在已被删除的Tweet,发送过Tweet的帐户已被暂停,等等。
您可以简单地处理每次调用TweepError
时产生的API.get_status
。
答案 1 :(得分:0)
您的代码中显然存在错误。您没有将正确的参数值传递给该函数。您传递的是 tweet_id ,而不是 id
这是您的代码的有效版本:
import tkinter as tk
from tkinter import ttk
class TreeviewTest(ttk.Frame):
def __init__(self, container, controller):
super().__init__(container)
self.list_num = ttk.Treeview(self, columns=("N"), show="tree headings",
height=20, selectmode="none")
self.list_num.heading(text="#", column=0, anchor=tk.W)
self.list_num["show"] = "headings"
self.list_num.column("#1",width=30 , minwidth=35, stretch=tk.YES)
self.refresh_csv_list()
self.list_num.grid(row=0, column=0, sticky="ew")
self.text = tk.Label(self, text="Sometext")
self.text.grid(row=0, column=1)
self.value = tk.DoubleVar()
self.style = ttk.Style()
self.style.layout("text.Horizontal.TProgressbar",
[("Horizontal.Progressbar.trough",
{"children": [("Horizontal.Progressbar.pbar",
{"side": "left", "sticky": "ns"})],
"sticky": "nswe"}),
("Horizontal.Progressbar.label", {"sticky": ""})])
self.h_list_num_scrollbar = ttk.Scrollbar(self, orient=tk.HORIZONTAL, command=self.list_num.xview)
self.h_list_num_scrollbar.grid(row=1, column=0, sticky="ew", columnspan=1)
self.list_num.configure(xscrollcommand = self.h_list_num_scrollbar.set)
self.pbar = ttk.Progressbar(self, orient="horizontal", length=300, maximum =100,
variable=self.value, style="text.Horizontal.TProgressbar")
self.pbar.grid(row=2, column=0, sticky="EW", pady=8, padx=3, columnspan=3)
self.update_progressbar(reset=True)
self.increment()
def increment(self):
self.update_progressbar(amount = 0.5)
self.after(20, self.increment)
def update_progressbar(self, amount=0, reset=False):
if reset:
new_value = 0
else:
new_value = self.value.get() + amount
if new_value < 0:
new_value = 0
if new_value > 100:
new_value = 100
self.value.set(new_value)
self.style.configure(style="text.Horizontal.TProgressbar",
text="{:.1f} %".format(self.value.get()))
def refresh_csv_list(self):
for i in range(50001000,50009000):
tg_num = f"tg_n__{i}"
self.list_num.insert("",i, text="",values=(str(i),) , tags=(tg_num,))
class MainPage(tk.Tk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.minsize(250,250)
self.title("Isolated GUI")
self.frames = dict()
container = ttk.Frame(self)
container.grid(padx=10, pady=10)
container.columnconfigure(0, weight=1)
frame_tree_view = TreeviewTest(container, self)
self.frames[TreeviewTest] = frame_tree_view
frame_tree_view.grid(row=0, column=0, sticky="NSEW")
self.show_frame(TreeviewTest)
def show_frame(self, container):
frame = self.frames[container]
frame.tkraise()
root = MainPage()
root.mainloop()