Skip to content

Latest commit

 

History

History
371 lines (268 loc) · 28.3 KB

File metadata and controls

371 lines (268 loc) · 28.3 KB

Trending

Overview

Available Operations

countries

Get the supported country and global options that can be used to filter trending tweets.

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.trending.countries();

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { XApiScraperCore } from "@twexapi-dev/x-api-scraper/core.js";
import { trendingCountries } from "@twexapi-dev/x-api-scraper/funcs/trending-countries.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 trendingCountries(xApiScraper);
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("trendingCountries failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
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.StandardResponse>

Errors

Error Type Status Code Content Type
errors.XAPIScraperDefaultError 4XX, 5XX */*

topics

Get the topic categories available for filtering global trending tweets.

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.trending.topics();

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { XApiScraperCore } from "@twexapi-dev/x-api-scraper/core.js";
import { trendingTopics } from "@twexapi-dev/x-api-scraper/funcs/trending-topics.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 trendingTopics(xApiScraper);
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("trendingTopics failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
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.StandardResponse>

Errors

Error Type Status Code Content Type
errors.XAPIScraperDefaultError 4XX, 5XX */*

contents

Get content tags for a selected country and topic so tweets can be filtered more precisely.

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.trending.contents({
    country: "Monaco",
    topic: "<value>",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { XApiScraperCore } from "@twexapi-dev/x-api-scraper/core.js";
import { trendingContents } from "@twexapi-dev/x-api-scraper/funcs/trending-contents.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 trendingContents(xApiScraper, {
    country: "Monaco",
    topic: "<value>",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("trendingContents failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.TrendingContentsRequest ✔️ 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.StandardResponse>

Errors

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

tweets

Get trending tweets for a country, with optional topic and content tag filters.

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.trending.tweets({
    country: "Lithuania",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { XApiScraperCore } from "@twexapi-dev/x-api-scraper/core.js";
import { trendingTweets } from "@twexapi-dev/x-api-scraper/funcs/trending-tweets.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 trendingTweets(xApiScraper, {
    country: "Lithuania",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("trendingTweets failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.TrendingTweetsRequest ✔️ 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.SearchResponse>

Errors

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

byCountry

Get X Explore trending topics for a given country. Use 'worldwide' for account-default trends or a country slug such as 'united-states'.

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.trending.byCountry({
    country: "worldwide",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { XApiScraperCore } from "@twexapi-dev/x-api-scraper/core.js";
import { trendingByCountry } from "@twexapi-dev/x-api-scraper/funcs/trending-by-country.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 trendingByCountry(xApiScraper, {
    country: "worldwide",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("trendingByCountry failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.TrendingByCountryRequest ✔️ 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.StandardResponse>

Errors

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