【问题标题】:NameError - name 'API' is not definedNameError - 名称“API”未定义
【发布时间】:2022-01-06 01:37:24
【问题描述】:

我正在尝试从 Twitter 抓取数据。但我总是有这个错误。我尝试了一切来解决这个问题,但没有任何效果。这是我的代码:

import tweepy
import re
import json
import pandas as pd
import numpy as np
from textblob import TextBlob
import nltk
import string

api_key = ""
api_secret_key = ""
access_token = ""
access_token_secret = ""

auth = tweepy.OAuthHandler(api_key, api_secret_key)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

hasilSearch = API.search_tweets(q="vaksin", lang="en", count=50)

我收到一个错误:NameError: name 'API' is not defined

【问题讨论】:

    标签: python tweepy


    【解决方案1】:

    正如错误所说,API 在最后一行使用时未定义。
    您需要使用已初始化的tweepy.API 实例api
    Python 区分大小写。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-24
      • 1970-01-01
      • 2021-04-15
      • 2019-01-26
      • 2021-10-05
      • 2017-08-16
      相关资源
      最近更新 更多