Trouble getting OAuth2 with user context #2140
-
QuestionI am struggling to get OAUTH2.0 user context access to get my bookmarks, and i keep getting an error telling me I need to user instead of application-only context despite me seemingly doing everything correctly to get OATH user context? is there something incorrect in my login function? Relevant Codedef login():
config = configparser.ConfigParser()
config.read('config.ini')
api_key = config['twitter']['api_key']
api_key_secret = config['twitter']['api_key_secret']
access_token = config['twitter']['access_token']
access_token_secret = config['twitter']['access_token_secret']
bearer_token = config['twitter']['bearer_token']
client_id = config['twitter']['client_id']
client_id_secret = config['twitter']['client_id_secret']
auth = tweepy.OAuth2UserHandler(
client_id=client_id,
redirect_uri="https://webhook.site/5f883830-afbb-4497-b647-b32dc0944947",
scope=["bookmark.read", "bookmark.write", "tweet.read", "users.read", "tweet.write"],
client_secret=client_id_secret
)
if config.has_option('twitter', 'access_token_pkce') or config.get('twitter', 'access_token_pkce'):
access_token_pkce = eval(config.get('twitter', 'access_token_pkce'))
else:
print(auth.get_authorization_url())
verifier = input("Paste the verifier here: ")
access_token_pkce = auth.fetch_token(verifier)
config.set('twitter', 'access_token_pkce', str(access_token_pkce))
with open('config.ini', 'w') as configfile:
config.write(configfile)
client = tweepy.Client(config["twitter"]["access_token_pkce"])
api = tweepy.API(auth)
return api, client Traceback/Users/joshuamendiola/PycharmProjects/JohmemesBot_Twitter/venv/bin/python /Users/joshuamendiola/PycharmProjects/JohmemesBot_Twitter/main.py
Traceback (most recent call last):
File "/Users/joshuamendiola/PycharmProjects/JohmemesBot_Twitter/main.py", line 64, in <module>
get_user_bookmarks()
File "/Users/joshuamendiola/PycharmProjects/JohmemesBot_Twitter/main.py", line 51, in get_user_bookmarks
bookmarks = user.get_bookmarks(
File "/Users/joshuamendiola/PycharmProjects/JohmemesBot_Twitter/venv/lib/python3.8/site-packages/tweepy/client.py", line 378, in get_bookmarks
id = self._get_authenticating_user_id()
File "/Users/joshuamendiola/PycharmProjects/JohmemesBot_Twitter/venv/lib/python3.8/site-packages/tweepy/client.py", line 260, in _get_authenticating_user_id
return self._get_oauth_2_authenticating_user_id(
File "/Users/joshuamendiola/PycharmProjects/JohmemesBot_Twitter/venv/lib/python3.8/site-packages/tweepy/client.py", line 275, in _get_oauth_2_authenticating_user_id
user_id = self.get_me(user_auth=False)["data"]["id"]
File "/Users/joshuamendiola/PycharmProjects/JohmemesBot_Twitter/venv/lib/python3.8/site-packages/tweepy/client.py", line 2443, in get_me
return self._make_request(
File "/Users/joshuamendiola/PycharmProjects/JohmemesBot_Twitter/venv/lib/python3.8/site-packages/tweepy/client.py", line 129, in _make_request
response = self.request(method, route, params=request_params,
File "/Users/joshuamendiola/PycharmProjects/JohmemesBot_Twitter/venv/lib/python3.8/site-packages/tweepy/client.py", line 100, in request
raise Forbidden(response)
tweepy.errors.Forbidden: 403 Forbidden
Authenticating with OAuth 2.0 Application-Only is forbidden for this endpoint. Supported authentication types are [OAuth 1.0a User Context, OAuth 2.0 User Context].
Process finished with exit code 1 Twitter API Access PlanBasic Tweepy Version4.14.0 Checklist
Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Answered by
Harmon758
Jul 5, 2023
Replies: 1 comment
-
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Harmon758
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
OAuth2UserHandler.fetch_token
should be returning a dictionary with the access token, not the access token itself as a string.