Table of Contents

Class GuestClient

Namespace
Twikit.Guest
Assembly
Twikit.dll

ゲスト(未ログイン)として Twitter API と対話するクライアント。

public sealed class GuestClient : IRequestClient, IRawHttpSession, IDisposable
Inheritance
GuestClient
Implements
Inherited Members

Remarks

2026 年現在、X はゲストアクセスを閉じています。 未ログインのリクエストには webpack マニフェストを 含まないページの殻しか返ってこないため、x-client-transaction-id のハンドシェイクが完了できず、 ActivateAsync() は InvalidSessionException を送出します。これはライブラリ側では直せません。 ログイン済みの Cookie を使う Client を利用してください。

Constructors

GuestClient(string, string?, HttpMessageHandler?)

public GuestClient(string language = "en-US", string? proxy = null, HttpMessageHandler? handler = null)

Parameters

language string

API リクエストで使う言語コード。

proxy string

プロキシの URL。

handler HttpMessageHandler

独自の HttpMessageHandler。

Properties

BaseHeaders

API リクエストの基本ヘッダー。

public Dictionary<string, string> BaseHeaders { get; }

Property Value

Dictionary<string, string>

ClientTransaction

public ClientTransaction ClientTransaction { get; }

Property Value

ClientTransaction

Cookies

Cookie ジャー。

public CookieContainer Cookies { get; }

Property Value

CookieContainer

Gql

public GqlClient Gql { get; }

Property Value

GqlClient

Http

実際に通信する HttpClient。

public HttpClient Http { get; }

Property Value

HttpClient

Language

API リクエストで使う言語コード。

public string Language { get; set; }

Property Value

string

Proxy

プロキシの URL。

public string? Proxy { get; }

Property Value

string

UserAgent

public string UserAgent { get; }

Property Value

string

V11

public V11Client V11 { get; }

Property Value

V11Client

Methods

ActivateAsync()

ゲストトークンを取得してクライアントを有効化します。

public Task<string> ActivateAsync()

Returns

Task<string>

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GetAsync(string, RequestOptions?)

public Task<ApiResponse> GetAsync(string url, RequestOptions? options = null)

Parameters

url string
options RequestOptions

Returns

Task<ApiResponse>

GetCsrfToken()

Cookie 中の CSRF トークン(ct0)。無ければ null。

public string? GetCsrfToken()

Returns

string

GetTweetByIdAsync(string)

ID を指定してツイートを取得します。

public Task<GuestTweet?> GetTweetByIdAsync(string tweetId)

Parameters

tweetId string

Returns

Task<GuestTweet>

GetUserByIdAsync(string)

ID を指定してユーザーを取得します。

public Task<GuestUser> GetUserByIdAsync(string userId)

Parameters

userId string

Returns

Task<GuestUser>

GetUserByScreenNameAsync(string)

スクリーンネームを指定してユーザーを取得します。

public Task<GuestUser> GetUserByScreenNameAsync(string screenName)

Parameters

screenName string

Returns

Task<GuestUser>

GetUserHighlightsTweetsAsync(string, int, string?)

ユーザーのハイライトツイートを取得します。

public Task<Result<GuestTweet>> GetUserHighlightsTweetsAsync(string userId, int count = 20, string? cursor = null)

Parameters

userId string
count int
cursor string

Returns

Task<Result<GuestTweet>>

GetUserTweetsAsync(string, string, int)

ユーザーのツイートを取得します。

public Task<List<GuestTweet>> GetUserTweetsAsync(string userId, string tweetType = "Tweets", int count = 40)

Parameters

userId string

ユーザー ID。

tweetType string

'Tweets' のみ。

count int

取得する件数。

Returns

Task<List<GuestTweet>>

PostAsync(string, RequestOptions?)

public Task<ApiResponse> PostAsync(string url, RequestOptions? options = null)

Parameters

url string
options RequestOptions

Returns

Task<ApiResponse>

RequestAsync(HttpMethod, string, RequestOptions?)

public Task<ApiResponse> RequestAsync(HttpMethod method, string url, RequestOptions? options = null)

Parameters

method HttpMethod
url string
options RequestOptions

Returns

Task<ApiResponse>

SendAsync(HttpMethod, string, RequestOptions?)

生のリクエスト(Python 版の _send)。メディアのダウンロードなどが使います。

public Task<HttpResponseMessage> SendAsync(HttpMethod method, string url, RequestOptions? options = null)

Parameters

method HttpMethod
url string
options RequestOptions

Returns

Task<HttpResponseMessage>