Skip to content

Latest commit

 

History

History
242 lines (164 loc) · 34.7 KB

File metadata and controls

242 lines (164 loc) · 34.7 KB

Dm

Overview

Available Operations

status

Retrieves the Direct Message (DM) availability status for a list of users. This endpoint checks if the specified accounts can receive messages based on their privacy settings, follow status, or verified permissions.

Example Usage

import os
from x_api_scraper import XapiScraper


with XapiScraper(
    bearer_auth=os.getenv("X_API_SCRAPER_BEARER_AUTH", ""),
) as xapi_scraper:

    res = xapi_scraper.dm.status(request=[
        "1696160451770429440",
    ])

    # Handle response
    print(res)

Parameters

Parameter Type Required Description
request List[str] ✔️ The request object to use for the request.
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.DMStatusResponseV2

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.XapiScraperDefaultError 4XX, 5XX */*

send

Send DM via XChat encrypted chat API (1:1 or existing group g...), optional image via media_urls (max 1) or video via video_url (mutually exclusive). $0.001 per call.

Example Usage

import os
from x_api_scraper import XapiScraper


with XapiScraper(
    bearer_auth=os.getenv("X_API_SCRAPER_BEARER_AUTH", ""),
) as xapi_scraper:

    res = xapi_scraper.dm.send(recipient="baker_donn80196", text="hello from docs", cookie="ct0=abc123... or 2c4a4e1832096aa694c739b83c83b6d96d43eba7", media_urls=[
        "https://example.com/image.jpg",
    ], video_url="https://video.twimg.com/amplify_video/2077160248830275584/vid/avc1/320x568/kwNDLTm", pin="1234", proxy="http://username:password@ip:port")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
recipient str ✔️ User id, @handle, or a group id (g...) for an existing group. baker_donn80196
text str ✔️ Message body. hello from docs
cookie str ✔️ Twitter authentication cookie or Twitter auth_token, how-to-get-twitter-cookie ct0=abc123... or 2c4a4e1832096aa694c739b83c83b6d96d43eba7
media_urls List[str] Public URL of one image to attach (max 1). Mutually exclusive with video_url. [
"https://example.com/image.jpg"
]
video_url OptionalNullable[str] Public http(s) URL of one video to attach (mutually exclusive with image). https://video.twimg.com/amplify_video/2077160248830275584/vid/avc1/320x568/kwNDLTm
pin OptionalNullable[str] Identity PIN (default 1234). 1234
proxy OptionalNullable[str] Optional HTTP proxy. Example: http://username:password@ip:port http://username:password@ip:port
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.SendDmResponse

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.XapiScraperDefaultError 4XX, 5XX */*

history

Get DM history via XChat encrypted chat API. Use count for page size (10–200). Set all=true to follow has_more and return every page. Or paginate manually: when has_more is true, pass the oldest message's sequence_id as before.

Example Usage

import os
from x_api_scraper import XapiScraper


with XapiScraper(
    bearer_auth=os.getenv("X_API_SCRAPER_BEARER_AUTH", ""),
) as xapi_scraper:

    res = xapi_scraper.dm.history(recipient="1928096185664843776:1989842918455291904", cookie="ct0=abc123... or 2c4a4e1832096aa694c739b83c83b6d96d43eba7", pin="1234", count=50, all=False, before="2076684837654876160", proxy="http://username:password@ip:port")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
recipient str ✔️ User id, @handle, conversationId a:b, or group g.... 1928096185664843776:1989842918455291904
cookie str ✔️ Twitter authentication cookie or Twitter auth_token, how-to-get-twitter-cookie ct0=abc123... or 2c4a4e1832096aa694c739b83c83b6d96d43eba7
pin OptionalNullable[str] Identity PIN (default 1234). 1234
count OptionalNullable[int] Max events per page (10–200, default 50). 50
all OptionalNullable[bool] Follow has_more and return every page. false
before OptionalNullable[str] Oldest sequenceId for paging. Pass the previous page's oldest message sequence_id. 2076684837654876160
proxy OptionalNullable[str] Optional HTTP proxy. Example: http://username:password@ip:port http://username:password@ip:port
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.GetDmHistoryV3Response

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.XapiScraperDefaultError 4XX, 5XX */*

media

Fetch one XChat media attachment and return a playable URL. Use conversation_id, media_hash_key, and optional key_version from /v3/twitter/dm-history attachments.

Example Usage

import os
from x_api_scraper import XapiScraper


with XapiScraper(
    bearer_auth=os.getenv("X_API_SCRAPER_BEARER_AUTH", ""),
) as xapi_scraper:

    res = xapi_scraper.dm.media(conversation_id="1928096185664843776:1989842918455291904", media_hash_key="blRIlZCVIO", cookie="ct0=abc123... or 2c4a4e1832096aa694c739b83c83b6d96d43eba7", key_version="3", type_name="VIDEO", filename="clip.mp4", pin="1234", proxy="http://username:password@ip:port")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
conversation_id str ✔️ Conversation id from /v3/twitter/dm-history 1928096185664843776:1989842918455291904
media_hash_key str ✔️ Attachment media_hash_key from dm-history blRIlZCVIO
cookie str ✔️ Twitter authentication cookie or Twitter auth_token, how-to-get-twitter-cookie ct0=abc123... or 2c4a4e1832096aa694c739b83c83b6d96d43eba7
key_version OptionalNullable[str] Optional message key_version from dm-history (recommended). 3
type_name OptionalNullable[str] Optional IMAGE/VIDEO/GIF hint VIDEO
filename OptionalNullable[str] Optional filename hint clip.mp4
pin OptionalNullable[str] Identity PIN (default 1234). 1234
proxy OptionalNullable[str] Optional HTTP proxy. Example: http://username:password@ip:port http://username:password@ip:port
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.GetDmMediaV3Response

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.XapiScraperDefaultError 4XX, 5XX */*

conversations

Get XChat conversation list. Use count for page size (10–200). Set all=true to follow the inbox cursor and return every conversation.

Example Usage

import os
from x_api_scraper import XapiScraper


with XapiScraper(
    bearer_auth=os.getenv("X_API_SCRAPER_BEARER_AUTH", ""),
) as xapi_scraper:

    res = xapi_scraper.dm.conversations(cookie="ct0=abc123... or 2c4a4e1832096aa694c739b83c83b6d96d43eba7", count=100, all=True, proxy="http://username:password@ip:port")

    # Handle response
    print(res)

Parameters

Parameter Type Required Description Example
cookie str ✔️ Twitter authentication cookie or Twitter auth_token, how-to-get-twitter-cookie ct0=abc123... or 2c4a4e1832096aa694c739b83c83b6d96d43eba7
count OptionalNullable[int] Max conversations per page (10–200, default 20). 100
all OptionalNullable[bool] Follow the inbox cursor and return every conversation (may be slow). true
proxy OptionalNullable[str] Optional HTTP proxy. Example: http://username:password@ip:port http://username:password@ip:port
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.GetConversationsV3Response

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.XapiScraperDefaultError 4XX, 5XX */*