如何从中检索多条tweetapi.statuses\查找/获取\状态

2024-05-16 00:57:39 发布

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

有一个包含tweet ID列表的变量,并且想要使用statuses\u lookup提取文本,但是当我执行时什么也没有出来

不知道我做错了什么?你知道吗

不确定是使用get\u status还是statuses\u lookup-假定为multiple-status

我想也许我需要一次输入一个,所以创建了变量alpha,当我用alpha替换tweetref时,它仍然不起作用

# Import twitter related packages
import json
import tweepy

from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream

#import request style packages

import requests
from urllib.request import urlopen, Request

# Import visualisation packages

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd

# Store OAuth authentication credentials in relevant variables
access_token = "priv"
access_token_secret = "priv"

consumer_key = "priv"
consumer_secret = "priv"

# Pass OAuth details to tweepy's OAuth handler

auth = tweepy.OAuthHandler("priv", "priv")
auth.set_access_token("priv", "priv")

api = tweepy.API(auth)

import xlrd
import openpyxl

#Read and write to excel
dataFileUrl = R"C:/Users/cbaba/Desktop/algeria1.xlsx"


data = pd.read_excel(dataFileUrl, usecols = ['Tweet'])
datalist = data.values.tolist()

tweetref = []

for t in range (0,1):
    tweetref.extend(datalist[40:50])


for x in range(len(tweetref)):
    try:
        alpha = tweetref[x]
        tweet = api.statuses_lookup(tweetref)
        print(tweet.text)

    except:
       pass

Tags: infromimportalphatokenaccesspackagesas