Skip to content

Latest commit

 

History

History
156 lines (113 loc) · 12.3 KB

File metadata and controls

156 lines (113 loc) · 12.3 KB

Articles

Overview

Available Operations

  • fetch - Batch Fetch X Articles
  • markdown - Fetch Article as Markdown

fetch

Retrieves detailed article content for a specified list of X (Twitter) IDs. Use this endpoint to fetch full text, metadata, and media links for multiple posts in a single request. The maximum input quantity is limited by your plan's QPS. To pass larger input quantity limits, upgrade your plan to get higher QPS.

Example Usage

import { XApiScraper } from "@twexapi-dev/x-api-scraper";

const xApiScraper = new XApiScraper({
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await xApiScraper.articles.fetch([
    "1803006263529541838",
  ]);

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { XApiScraperCore } from "@twexapi-dev/x-api-scraper/core.js";
import { articlesFetch } from "@twexapi-dev/x-api-scraper/funcs/articles-fetch.js";

// Use `XApiScraperCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const xApiScraper = new XApiScraperCore({
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await articlesFetch(xApiScraper, [
    "1803006263529541838",
  ]);
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("articlesFetch failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request string[] ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<models.XArticleResponse>

Errors

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

markdown

Retrieves the content of an X (Twitter) article formatted as clean, valid Markdown. The response body is delivered as a raw UTF-8 string, optimized for direct import into static site generators, Obsidian, Notion, or any standard Markdown editor.

Example Usage

import { XApiScraper } from "@twexapi-dev/x-api-scraper";

const xApiScraper = new XApiScraper({
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await xApiScraper.articles.markdown({
    tweetId: "<id>",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { XApiScraperCore } from "@twexapi-dev/x-api-scraper/core.js";
import { articlesMarkdown } from "@twexapi-dev/x-api-scraper/funcs/articles-markdown.js";

// Use `XApiScraperCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const xApiScraper = new XApiScraperCore({
  bearerAuth: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await articlesMarkdown(xApiScraper, {
    tweetId: "<id>",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("articlesMarkdown failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.ArticlesMarkdownRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<string>

Errors

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