#2200·tweepy

get_bookmarks 403 Forbidden: Authenticating with OAuth 2.0 Application-Only is forbidden for this endpoint

Author: dxaviudCreated Aug 9, 2024Updated Jan 15, 2025
LabelsUnconfirmed Bug

Summary

Client.get_bookmarks can't authenticate properly

Reproduction Steps

roughly do this

client = tweepy.Client(
    bearer_token=BEARER_TOKEN,
    consumer_key=API_KEY,
    consumer_secret=API_SECRET_KEY,
    access_token=ACCESS_TOKEN,
    access_token_secret=ACCESS_TOKEN_SECRET,
)
...
response = client.get_bookmarks(
    max_results=100,
    pagination_token=None,
    tweet_fields=['created_at', 'public_metrics']
)

Minimal Reproducible Example

python
from dotenv import load_dotenv
import os
import tweepy

load_dotenv()

BEARER_TOKEN = os.getenv("BEARER_TOKEN")
API_KEY = os.getenv("API_KEY")
API_SECRET_KEY = os.getenv("API_SECRET_KEY")
ACCESS_TOKEN = os.getenv("ACCESS_TOKEN")
ACCESS_TOKEN_SECRET = os.getenv("ACCESS_TOKEN_SECRET")

client = tweepy.Client(
    bearer_token=BEARER_TOKEN,
    consumer_key=API_KEY,
    consumer_secret=API_SECRET_KEY,
    access_token=ACCESS_TOKEN,
    access_token_secret=ACCESS_TOKEN_SECRET,
)

response = client.get_bookmarks()

Note: I can also remove everything except bearer_token and I get the same issue. If I remove bearer_token and keep the other four, then I get a different exception: TypeError: Access Token must be provided for OAuth 2.0 Authorization Code Flow with PKCE

Expected Results

for the client to return bookmarks for my authenticated user

Actual Results

exception throw: 403 Forbidden: Authenticating with OAuth 2.0 Application-Only is forbidden for this endpoint

Twitter API Access Plan

Basic

Tweepy Version

4.14.0

Checklist

  • I have searched for duplicate issues.
  • If applicable, I have shown the entire traceback.
  • If applicable, I have removed any visible credentials from my code and/or screenshots.

Additional Context

trace:

    response = client.get_bookmarks(
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dxavi\AppData\Local\Programs\Python\Python312\Lib\site-packages\tweepy\client.py", line 374, in get_bookmarks
    id = self._get_authenticating_user_id()
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dxavi\AppData\Local\Programs\Python\Python312\Lib\site-packages\tweepy\client.py", line 256, in _get_authenticating_user_id
    return self._get_oauth_2_authenticating_user_id(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dxavi\AppData\Local\Programs\Python\Python312\Lib\site-packages\tweepy\client.py", line 271, in _get_oauth_2_authenticating_user_id
    user_id = self.get_me(user_auth=False)["data"]["id"]
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dxavi\AppData\Local\Programs\Python\Python312\Lib\site-packages\tweepy\client.py", line 2535, in get_me
    return self._make_request(
           ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dxavi\AppData\Local\Programs\Python\Python312\Lib\site-packages\tweepy\client.py", line 129, in _make_request
    response = self.request(method, route, params=request_params,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\dxavi\AppData\Local\Programs\Python\Python312\Lib\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].