Table of Contents

Class ClientTransaction

Namespace
Twikit.Transaction
Assembly
Twikit.dll

X-Client-Transaction-Id ヘッダーの生成。

public sealed class ClientTransaction
Inheritance
ClientTransaction
Inherited Members

Remarks

このプロジェクトには次のオープンソースプロジェクトのコードが含まれています: https://github.com/iSarabjitDhiman/TweeterPy — 原作者の尽力に深く感謝します。

ホームページの twitter-site-verification メタタグと loading-x-anim-* の SVG、 および webpack の ondemand.s チャンクから読み取ったインデックスを組み合わせて 「アニメーションキー」を計算し、リクエストごとにメソッド・パス・時刻を混ぜた ID を作ります。

Fields

AdditionalRandomNumber

public const int AdditionalRandomNumber = 3

Field Value

int

DefaultKeyword

public const string DefaultKeyword = "obfiowerehiring"

Field Value

string

Properties

AnimationKey

public string? AnimationKey { get; }

Property Value

string

DefaultKeyBytesIndices

ondemand.s から読んだフレーム時間計算用のキーバイト添字。

public int[]? DefaultKeyBytesIndices { get; }

Property Value

int[]

DefaultRowIndex

ondemand.s から読んだ行インデックス(キーバイトの添字)。

public int? DefaultRowIndex { get; }

Property Value

int?

HomePageResponse

ハンドシェイクで取得したホームページ。

public HomePage? HomePageResponse { get; }

Property Value

HomePage

Key

twitter-site-verification のキー。

public string? Key { get; }

Property Value

string

KeyBytes

public byte[]? KeyBytes { get; }

Property Value

byte[]

Methods

Animate(IReadOnlyList<int>, double)

フレーム行と目標時刻からアニメーションキーを計算します。

public string Animate(IReadOnlyList<int> frames, double targetTime)

Parameters

frames IReadOnlyList<int>
targetTime double

Returns

string

GenerateTransactionId(string, string, HomePage?, string?, string?, long?, int?)

リクエスト 1 件分の X-Client-Transaction-Id を生成します。

public string GenerateTransactionId(string method, string path, HomePage? page = null, string? key = null, string? animationKey = null, long? timeNow = null, int? randomNumber = null)

Parameters

method string

HTTP メソッド(大文字)。

path string

URL のパス部分。

page HomePage

ハンドシェイク済みでない場合に使うホームページ。

key string

明示的なキー。

animationKey string

明示的なアニメーションキー。

timeNow long?

明示的な時刻(テスト用、2023-05-01 からの秒数)。

randomNumber int?

明示的な乱数(テスト用、0-255)。

Returns

string

Get2dArray(byte[], HomePage?, IHtmlCollection<IElement>?)

選んだフレームの 2 つ目の path の d 属性を "C" で区切って数値の 2 次元配列にします。

public List<List<int>> Get2dArray(byte[] keyBytes, HomePage? page = null, IHtmlCollection<IElement>? frames = null)

Parameters

keyBytes byte[]
page HomePage
frames IHtmlCollection<IElement>

Returns

List<List<int>>

GetAnimationKey(byte[], HomePage?)

キーバイトとホームページからアニメーションキーを求めます。

public string GetAnimationKey(byte[] keyBytes, HomePage? page = null)

Parameters

keyBytes byte[]
page HomePage

Returns

string

GetFrames(HomePage?)

loading-x-anim-0 ~ loading-x-anim-3 の要素。

public IHtmlCollection<IElement> GetFrames(HomePage? page = null)

Parameters

page HomePage

Returns

IHtmlCollection<IElement>

GetIndicesAsync(HomePage?, IRawHttpSession, Dictionary<string, string>)

ホームページの webpack チャンクマップから ondemand.s のハッシュを見つけ、 そのファイルから KEY_BYTE のインデックスを読みます。

public Task<(int RowIndex, int[] KeyBytesIndices)> GetIndicesAsync(HomePage? homePage, IRawHttpSession session, Dictionary<string, string> headers)

Parameters

homePage HomePage
session IRawHttpSession
headers Dictionary<string, string>

Returns

Task<(int RowIndex, int[] KeyBytesIndices)>

GetKey(HomePage?)

twitter-site-verification メタタグからキーを読みます。

public string GetKey(HomePage? page = null)

Parameters

page HomePage

Returns

string

GetKeyBytes(string)

public static byte[] GetKeyBytes(string key)

Parameters

key string

Returns

byte[]

InitAsync(IRawHttpSession, Dictionary<string, string>)

ハンドシェイクを実行します(同時呼び出しは直列化されます)。

public Task InitAsync(IRawHttpSession session, Dictionary<string, string> headers)

Parameters

session IRawHttpSession
headers Dictionary<string, string>

Returns

Task

IsInited()

ハンドシェイクが完了しているか。

public bool IsInited()

Returns

bool

Reset()

ハンドシェイクを忘れ、次のリクエストでやり直させます。

public void Reset()

Remarks

キーは X が数日ごとに入れ替える webpack バンドルに由来し、取得したセッションにも 紐付いています。Cookie を入れ替えた後も古いキーで作った ID は X に黙って 404 を返されます。

Solve(double, double, double, bool)

public static double Solve(double value, double minVal, double maxVal, bool rounding)

Parameters

value double
minVal double
maxVal double
rounding bool

Returns

double