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
DefaultKeyword
public const string DefaultKeyword = "obfiowerehiring"
Field Value
Properties
AnimationKey
public string? AnimationKey { get; }
Property Value
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
Key
twitter-site-verification のキー。
public string? Key { get; }
Property Value
KeyBytes
public byte[]? KeyBytes { get; }
Property Value
- byte[]
Methods
Animate(IReadOnlyList<int>, double)
フレーム行と目標時刻からアニメーションキーを計算します。
public string Animate(IReadOnlyList<int> frames, double targetTime)
Parameters
framesIReadOnlyList<int>targetTimedouble
Returns
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
methodstringHTTP メソッド(大文字)。
pathstringURL のパス部分。
pageHomePageハンドシェイク済みでない場合に使うホームページ。
keystring明示的なキー。
animationKeystring明示的なアニメーションキー。
timeNowlong?明示的な時刻(テスト用、2023-05-01 からの秒数)。
randomNumberint?明示的な乱数(テスト用、0-255)。
Returns
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
Returns
GetAnimationKey(byte[], HomePage?)
キーバイトとホームページからアニメーションキーを求めます。
public string GetAnimationKey(byte[] keyBytes, HomePage? page = null)
Parameters
Returns
GetFrames(HomePage?)
loading-x-anim-0 ~ loading-x-anim-3 の要素。
public IHtmlCollection<IElement> GetFrames(HomePage? page = null)
Parameters
pageHomePage
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
homePageHomePagesessionIRawHttpSessionheadersDictionary<string, string>
Returns
- Task<(int RowIndex, int[] KeyBytesIndices)>
GetKey(HomePage?)
twitter-site-verification メタタグからキーを読みます。
public string GetKey(HomePage? page = null)
Parameters
pageHomePage
Returns
GetKeyBytes(string)
public static byte[] GetKeyBytes(string key)
Parameters
keystring
Returns
- byte[]
InitAsync(IRawHttpSession, Dictionary<string, string>)
ハンドシェイクを実行します(同時呼び出しは直列化されます)。
public Task InitAsync(IRawHttpSession session, Dictionary<string, string> headers)
Parameters
sessionIRawHttpSessionheadersDictionary<string, string>
Returns
IsInited()
ハンドシェイクが完了しているか。
public bool IsInited()
Returns
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)