I am trying to connect to Twitter API (tweepy) but it does not seem to work
my views.py
class TwitterAPI(APIView):
def get(self, request):
consumer_key = 'XXX'
consumer_secret = 'XXX'
access_token = 'XXX'
access_token_secret = 'XXX'
auth = tw.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
tw.API(auth, wait_on_rate_limit=True)
return Response('OK')
urls.py
urlpatterns = [
path(
"auth/twitter/redirect/",
views.TwitterAPI.as_view(),
)
]
When I try tto access the url it throws an error Exception Type: NameError Exception Value: name 'Response' is not defined
When I tried to change the class, not tu use get, it also throws an error like GET is not allowed
Sorry I really can't get how to connect to the twitter api in rest framwork
The error occurs because Response is not defined. Fix the error by import Response first. Define the snippet below at the top of your class TwitterAPI
from rest_framework.response import Response
Try Importing the response function
from rest_framework.response import Response
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With