twitteropenapipython_generated

May 20, 2026 ยท View on GitHub

Twitter OpenAPI(Swagger) specification

This Python package is automatically generated by the OpenAPI Generator project:

  • API version: 0.0.1
  • Package version: 0.0.34
  • Generator version: 7.22.0
  • Build package: org.openapitools.codegen.languages.PythonClientCodegen

Requirements.

Python 3.10+

Installation & Usage

pip install

If the python package is hosted on a repository, you can install directly using:

pip install git+https://github.com/fa0311/twitter_openapi_python.git

(you may need to run pip with root permission: sudo pip install git+https://github.com/fa0311/twitter_openapi_python.git)

Then import the package:

import twitter_openapi_python_generated

Setuptools

Install via Setuptools.

python setup.py install --user

(or sudo python setup.py install to install the package for all users)

Then import the package:

import twitter_openapi_python_generated

Tests

Execute pytest to run the tests.

Getting Started

Please follow the installation procedure and then run the following:


import twitter_openapi_python_generated
from twitter_openapi_python_generated.rest import ApiException
from pprint import pprint

# Defining the host is optional and defaults to https://x.com/i/api
# See configuration.py for a list of all supported configuration parameters.
configuration = twitter_openapi_python_generated.Configuration(
    host = "https://x.com/i/api"
)

# The client must configure the authentication and authorization parameters
# in accordance with the API server security policy.
# Examples for each auth method are provided below, use the example that
# satisfies your auth use case.

# Configure API key authorization: Accept
configuration.api_key['Accept'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['Accept'] = 'Bearer'

# Configure API key authorization: ClientLanguage
configuration.api_key['ClientLanguage'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['ClientLanguage'] = 'Bearer'

# Configure API key authorization: Priority
configuration.api_key['Priority'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['Priority'] = 'Bearer'

# Configure API key authorization: Referer
configuration.api_key['Referer'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['Referer'] = 'Bearer'

# Configure API key authorization: SecFetchDest
configuration.api_key['SecFetchDest'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['SecFetchDest'] = 'Bearer'

# Configure API key authorization: SecChUaPlatform
configuration.api_key['SecChUaPlatform'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['SecChUaPlatform'] = 'Bearer'

# Configure API key authorization: SecFetchMode
configuration.api_key['SecFetchMode'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['SecFetchMode'] = 'Bearer'

# Configure API key authorization: CsrfToken
configuration.api_key['CsrfToken'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['CsrfToken'] = 'Bearer'

# Configure API key authorization: ClientUuid
configuration.api_key['ClientUuid'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['ClientUuid'] = 'Bearer'

# Configure Bearer authorization: BearerAuth
configuration = twitter_openapi_python_generated.Configuration(
    access_token = os.environ["BEARER_TOKEN"]
)

# Configure API key authorization: GuestToken
configuration.api_key['GuestToken'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['GuestToken'] = 'Bearer'

# Configure API key authorization: SecChUa
configuration.api_key['SecChUa'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['SecChUa'] = 'Bearer'

# Configure API key authorization: CookieGt0
configuration.api_key['CookieGt0'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['CookieGt0'] = 'Bearer'

# Configure API key authorization: ClientTransactionId
configuration.api_key['ClientTransactionId'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['ClientTransactionId'] = 'Bearer'

# Configure API key authorization: ActiveUser
configuration.api_key['ActiveUser'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['ActiveUser'] = 'Bearer'

# Configure API key authorization: CookieCt0
configuration.api_key['CookieCt0'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['CookieCt0'] = 'Bearer'

# Configure API key authorization: UserAgent
configuration.api_key['UserAgent'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['UserAgent'] = 'Bearer'

# Configure API key authorization: AcceptLanguage
configuration.api_key['AcceptLanguage'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['AcceptLanguage'] = 'Bearer'

# Configure API key authorization: SecFetchSite
configuration.api_key['SecFetchSite'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['SecFetchSite'] = 'Bearer'

# Configure API key authorization: AuthType
configuration.api_key['AuthType'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['AuthType'] = 'Bearer'

# Configure API key authorization: CookieAuthToken
configuration.api_key['CookieAuthToken'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['CookieAuthToken'] = 'Bearer'

# Configure API key authorization: SecChUaMobile
configuration.api_key['SecChUaMobile'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['SecChUaMobile'] = 'Bearer'

# Configure API key authorization: AcceptEncoding
configuration.api_key['AcceptEncoding'] = os.environ["API_KEY"]

# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['AcceptEncoding'] = 'Bearer'


# Enter a context with an instance of the API client
with twitter_openapi_python_generated.ApiClient(configuration) as api_client:
    # Create an instance of the API class
    api_instance = twitter_openapi_python_generated.DefaultApi(api_client)
    path_query_id = 'mzoqrVGwk-YTSGME1dRfXQ' # str |  (default to 'mzoqrVGwk-YTSGME1dRfXQ')
    variables = '{"screen_name": "elonmusk"}' # str |  (default to '{"screen_name": "elonmusk"}')
    features = '{}' # str |  (default to '{}')

    try:
        api_response = api_instance.get_profile_spotlights_query(path_query_id, variables, features)
        print("The response of DefaultApi->get_profile_spotlights_query:\n")
        pprint(api_response)
    except ApiException as e:
        print("Exception when calling DefaultApi->get_profile_spotlights_query: %s\n" % e)

Documentation for API Endpoints

All URIs are relative to https://x.com/i/api

ClassMethodHTTP requestDescription
DefaultApiget_profile_spotlights_queryGET /graphql/{pathQueryId}/ProfileSpotlightsQuery
DefaultApiget_tweet_result_by_rest_idGET /graphql/{pathQueryId}/TweetResultByRestId
OtherApiotherGET /other
PostApipost_create_bookmarkPOST /graphql/{pathQueryId}/CreateBookmark
PostApipost_create_retweetPOST /graphql/{pathQueryId}/CreateRetweet
PostApipost_create_tweetPOST /graphql/{pathQueryId}/CreateTweet
PostApipost_delete_bookmarkPOST /graphql/{pathQueryId}/DeleteBookmark
PostApipost_delete_retweetPOST /graphql/{pathQueryId}/DeleteRetweet
PostApipost_delete_tweetPOST /graphql/{pathQueryId}/DeleteTweet
PostApipost_favorite_tweetPOST /graphql/{pathQueryId}/FavoriteTweet
PostApipost_unfavorite_tweetPOST /graphql/{pathQueryId}/UnfavoriteTweet
TweetApiget_bookmarksGET /graphql/{pathQueryId}/Bookmarks
TweetApiget_community_about_timelineGET /graphql/{pathQueryId}/CommunityAboutTimeline
TweetApiget_community_media_timelineGET /graphql/{pathQueryId}/CommunityMediaTimeline
TweetApiget_community_tweets_timelineGET /graphql/{pathQueryId}/CommunityTweetsTimeline
TweetApiget_home_latest_timelineGET /graphql/{pathQueryId}/HomeLatestTimeline
TweetApiget_home_timelineGET /graphql/{pathQueryId}/HomeTimeline
TweetApiget_likesGET /graphql/{pathQueryId}/Likes
TweetApiget_list_latest_tweets_timelineGET /graphql/{pathQueryId}/ListLatestTweetsTimeline
TweetApiget_notifications_timelineGET /graphql/{pathQueryId}/NotificationsTimeline
TweetApiget_search_timelineGET /graphql/{pathQueryId}/SearchTimeline
TweetApiget_tweet_detailGET /graphql/{pathQueryId}/TweetDetail
TweetApiget_user_highlights_tweetsGET /graphql/{pathQueryId}/UserHighlightsTweets
TweetApiget_user_mediaGET /graphql/{pathQueryId}/UserMedia
TweetApiget_user_tweetsGET /graphql/{pathQueryId}/UserTweets
TweetApiget_user_tweets_and_repliesGET /graphql/{pathQueryId}/UserTweetsAndReplies
UserApiget_user_by_rest_idGET /graphql/{pathQueryId}/UserByRestId
UserApiget_user_by_screen_nameGET /graphql/{pathQueryId}/UserByScreenName
UserListApiget_blue_verified_followersGET /graphql/{pathQueryId}/BlueVerifiedFollowers
UserListApiget_favoritersGET /graphql/{pathQueryId}/Favoriters
UserListApiget_followersGET /graphql/{pathQueryId}/Followers
UserListApiget_followers_you_knowGET /graphql/{pathQueryId}/FollowersYouKnow
UserListApiget_followingGET /graphql/{pathQueryId}/Following
UserListApiget_retweetersGET /graphql/{pathQueryId}/Retweeters
UsersApiget_users_by_rest_idsGET /graphql/{pathQueryId}/UsersByRestIds
V11GetApiget_friends_following_listGET /1.1/friends/following/list.json
V11GetApiget_search_typeaheadGET /1.1/search/typeahead.json
V11PostApipost_create_friendshipsPOST /1.1/friendships/create.json
V11PostApipost_destroy_friendshipsPOST /1.1/friendships/destroy.json
V20GetApiget_search_adaptiveGET /2/search/adaptive.json

Documentation For Models

Documentation For Authorization

Authentication schemes defined for the API:

Accept

  • Type: API key
  • API key parameter name: Accept
  • Location: HTTP header

AcceptEncoding

  • Type: API key
  • API key parameter name: Accept-Encoding
  • Location: HTTP header

AcceptLanguage

  • Type: API key
  • API key parameter name: Accept-Language
  • Location: HTTP header

ActiveUser

  • Type: API key
  • API key parameter name: x-twitter-active-user
  • Location: HTTP header

AuthType

  • Type: API key
  • API key parameter name: x-twitter-auth-type
  • Location: HTTP header

BearerAuth

  • Type: Bearer authentication

ClientLanguage

  • Type: API key
  • API key parameter name: x-twitter-client-language
  • Location: HTTP header

ClientTransactionId

  • Type: API key
  • API key parameter name: x-client-transaction-id
  • Location: HTTP header

ClientUuid

  • Type: API key
  • API key parameter name: x-client-uuid
  • Location: HTTP header

CookieAuthToken

  • Type: API key
  • API key parameter name: auth_token
  • Location:

CookieCt0

  • Type: API key
  • API key parameter name: ct0
  • Location:

CookieGt0

  • Type: API key
  • API key parameter name: gt0
  • Location:

CsrfToken

  • Type: API key
  • API key parameter name: x-csrf-token
  • Location: HTTP header

GuestToken

  • Type: API key
  • API key parameter name: x-guest-token
  • Location: HTTP header

Priority

  • Type: API key
  • API key parameter name: Priority
  • Location: HTTP header

Referer

  • Type: API key
  • API key parameter name: Referer
  • Location: HTTP header

SecChUa

  • Type: API key
  • API key parameter name: Sec-Ch-Ua
  • Location: HTTP header

SecChUaMobile

  • Type: API key
  • API key parameter name: Sec-Ch-Ua-Mobile
  • Location: HTTP header

SecChUaPlatform

  • Type: API key
  • API key parameter name: Sec-Ch-Ua-Platform
  • Location: HTTP header

SecFetchDest

  • Type: API key
  • API key parameter name: Sec-Fetch-Dest
  • Location: HTTP header

SecFetchMode

  • Type: API key
  • API key parameter name: Sec-Fetch-Mode
  • Location: HTTP header

SecFetchSite

  • Type: API key
  • API key parameter name: Sec-Fetch-Site
  • Location: HTTP header

UserAgent

  • Type: API key
  • API key parameter name: user-agent
  • Location: HTTP header

Author

yuki@yuki0311.com