tonhowtf/omniget · error

Guest token ausente na resposta

Error message

Guest token ausente na resposta

What it means

Thrown in get_guest_token when the guest activation endpoint returns HTTP 200 but the JSON body has no string "guest_token" field. The library expects {"guest_token": "..."}; any other shape is unusable and triggers this error.

Solutions

  1. Log the raw response body to inspect what was returned
  2. Check whether the response is actually JSON (content-type) and not an HTML challenge
  3. Refresh the Bearer token used for activation
  4. Cache is written only on success — clear any stale guest_token cache and retry

Example fix

// before
let token = json.get("guest_token").and_then(|v| v.as_str()).ok_or_else(|| anyhow!("Guest token ausente na resposta"))?.to_string();
// after
let token = json.get("guest_token")
    .and_then(|v| v.as_str())
    .ok_or_else(|| anyhow!("Guest token ausente na resposta: {}", json))?
    .to_string();
Defensive patterns

Strategy: validation

Validate before calling

// inspect body before trusting it
let is_token_response = |j: &serde_json::Value| j.get("guest_token").and_then(|v| v.as_str()).is_some();

Type guard

fn extract_guest_token(json: &serde_json::Value) -> Option<&str> {
    json.get("guest_token").and_then(|v| v.as_str())
}

Prevention

When it happens

Trigger: Twitter returned success status but a JSON body without guest_token — e.g. an HTML error page parsed as JSON, or an API schema change.

Common situations: Bot-detection responses (200 with empty/challenge body); Twitter API response shape change; CDN interception pages behind a proxy.

Related errors


AI-assisted analysis of tonhowtf/omniget@8600b91f42 (2026-09-12). Data as JSON: /api/errors/af75af0f0783c543. Report an issue: GitHub.

Appendix: source

Thrown at src-tauri/omniget-core/src/platforms/twitter.rs:237

            .header("Authorization", BEARER)
            .header("x-twitter-client-language", "en")
            .header("x-twitter-active-user", "yes")
            .header("Accept-Language", "en")
            .send()
            .await?;

        if !response.status().is_success() {
            return Err(anyhow!(
                "Falha ao obter guest token: HTTP {}",
                response.status()
            ));
        }

        let json: serde_json::Value = response.json().await?;
        let token = json
            .get("guest_token")
            .and_then(|v| v.as_str())
            .ok_or_else(|| anyhow!("Guest token ausente na resposta"))?
            .to_string();

        let mut cached = self.guest_token.lock().await;
        *cached = Some(token.clone());
        Ok(token)
    }

    async fn request_tweet(
        &self,
        tweet_id: &str,
        guest_token: &str,
    ) -> anyhow::Result<serde_json::Value> {
        let variables = serde_json::json!({
            "focalTweetId": tweet_id,
            "with_rux_injections": false,
            "rankingMode": "Relevance",
            "includePromotedContent": true,
            "withCommunity": true,

View on GitHub (pinned to 8600b91f42)