-
Just following the tutorial here, trying to use Client for APIv2 calls, and getting this: Traceback (most recent call last):
File "/home/k/prj/videosdb/backend/.venv/lib/python3.10/site-packages/aiounittest/helpers.py", line 138, in decorator
return loop.run_until_complete(future)
File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
return future.result()
File "/home/k/prj/videosdb/backend/tests/test_downloader.py", line 168, in test_hello_twitter
await p.publish_tweets()
File "/home/k/prj/videosdb/backend/videosdb/publisher.py", line 18, in publish_tweets
self.client.create_tweet(text="hi")
File "/home/k/prj/videosdb/backend/.venv/lib/python3.10/site-packages/tweepy/client.py", line 824, in create_tweet
return self._make_request(
File "/home/k/prj/videosdb/backend/.venv/lib/python3.10/site-packages/tweepy/client.py", line 126, in _make_request
response = self.request(method, route, params=request_params,
File "/home/k/prj/videosdb/backend/.venv/lib/python3.10/site-packages/tweepy/client.py", line 68, in request
auth = OAuth1UserHandler(
File "/home/k/prj/videosdb/backend/.venv/lib/python3.10/site-packages/tweepy/auth.py", line 31, in __init__
raise TypeError("Consumer key must be string or bytes, not "
TypeError: Consumer key must be string or bytes, not NoneType My code is: definition: class Publisher:
def __init__(self) -> None:
self.db = DB()
self.client = Client(TWITTER_KEYS["bearer token"])
def publish_tweets(self):
self.client.create_tweet(text="hi") usage: p = Publisher()
p.publish_tweets() No idea what is going on here. What do you thing, guys? Thank you for your time. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If you're using a OAuth 2.0 Authorization Code Flow with PKCE access token, you can set the Otherwise, an app-only bearer token by definition is app-only and doesn't have user context, so it can't be used to perform actions on the behalf of a user, such as creating a Tweet. |
Beta Was this translation helpful? Give feedback.
Client.create_tweet
uses OAuth 1.0a User Context by default. The error occurs because you don't provide a consumer key, consumer secret, access token, or access token secret, and without those credentials, the method can't use OAuth 1.0 User Context.If you're using a OAuth 2.0 Authorization Code Flow with PKCE access token, you can set the
user_auth
parameter toFalse
, to use the access token to authenticate instead.Otherwise, an app-only bearer token by definition is app-only and doesn't have user context, so it can't be used to perform actions on the behalf of a user, such as creating a Tweet.