Alya Haryanti
Alya Haryanti

Reputation: 1

NameError - name 'API' is not defined

I am trying to do my homework which is crawling data from Twitter. But I always have this error. I tried everything to solve this but nothing works. This is my code:

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)

I'm getting an error: NameError: name 'API' is not defined

Upvotes: 0

Views: 2317

Answers (1)

Harmon758
Harmon758

Reputation: 5157

As the error says, API is undefined when you use it on the last line.
You need to use the instance of tweepy.API that you have initialized, api.
Python is case-sensitive.

Upvotes: 2

Related Questions