Skip to content

Commit

Permalink
update domain from twitter.com to x.com (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
melvinmcrn authored May 20, 2024
1 parent 1022671 commit 8dc65e6
Show file tree
Hide file tree
Showing 20 changed files with 223 additions and 223 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Twitter API v2

[![Twitter API v2 badge](https://img.shields.io/endpoint?url=https%3A%2F%2Ftwbadges.glitch.me%2Fbadges%2Fv2)](https://developer.twitter.com/en/docs/twitter-api/early-access)
[![Twitter API v1.1 badge](https://img.shields.io/endpoint?url=https%3A%2F%2Ftwbadges.glitch.me%2Fbadges%2Fstandard)](https://developer.twitter.com/en/docs/twitter-api/v1)
[![Twitter API v2 badge](https://img.shields.io/endpoint?url=https%3A%2F%2Ftwbadges.glitch.me%2Fbadges%2Fv2)](https://developer.x.com/en/docs/twitter-api/early-access)
[![Twitter API v1.1 badge](https://img.shields.io/endpoint?url=https%3A%2F%2Ftwbadges.glitch.me%2Fbadges%2Fstandard)](https://developer.x.com/en/docs/twitter-api/v1)
[![Version badge](https://badgen.net/github/release/PLhery/node-twitter-api-v2)](https://github.com/PLhery/node-twitter-api-v2)
[![Checks badge](https://github.com/PLhery/node-twitter-api-v2/actions/workflows/CI.yml/badge.svg)](https://github.com/PLhery/node-twitter-api-v2/actions/workflows/CI.yml)
[![Package size badge](https://badgen.net/bundlephobia/minzip/twitter-api-v2)](https://bundlephobia.com/package/twitter-api-v2)
Expand All @@ -12,7 +12,7 @@ Main maintainer: [@alkihis](https://github.com/alkihis) - <a href="https://www.b

## Important Note

Twitter will significantly reduce its API capabilities by end of April ([see this thread](https://twitter.com/TwitterDev/status/1641222782594990080)).
Twitter will significantly reduce its API capabilities by end of April ([see this thread](https://x.com/TwitterDev/status/1641222782594990080)).

This change has major implications, and as a result, this library may no longer be maintained.

Expand Down
4 changes: 2 additions & 2 deletions doc/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ const v2LabsClient = client.v2.labs;
```

Using the versioned client **auto-prefix requests** with default prefixes
(for v1: `https://api.twitter.com/1.1/`, for v2: `https://api.twitter.com/2/`,
for labs v2: `https://api.twitter.com/labs/2/`)
(for v1: `https://api.x.com/1.1/`, for v2: `https://api.x.com/2/`,
for labs v2: `https://api.x.com/labs/2/`)
and this gives you access to endpoint-wrapper methods!

## Use the endpoint-wrapper methods
Expand Down
8 changes: 4 additions & 4 deletions doc/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ console.log('Refresh token to store for client:', refreshToken);
## HTTP wrappers

You can directly use HTTP wrappers to make custom requests.
Requests under `.v1` are prefixed with `https://api.twitter.com/1.1/`, and under `.v2` are prefixed with `https://api.twitter/2/`.
Requests under `.v1` are prefixed with `https://api.x.com/1.1/`, and under `.v2` are prefixed with `https://api.twitter/2/`.

It means that if you need to use a different domain, for example `https://upload.twitter.com/1.1/`, you **must specify it manually** (see below).
It means that if you need to use a different domain, for example `https://upload.x.com/1.1/`, you **must specify it manually** (see below).

### Make a GET HTTP request to a Twitter endpoint

Expand All @@ -339,7 +339,7 @@ console.log(result.data); // TweetV2[]
const mediaStatus = await client.v1.get<MediaStatusV1Result>(
'media/upload.json',
{ command: 'STATUS', media_id: '20' },
{ prefix: 'https://upload.twitter.com/1.1/' },
{ prefix: 'https://upload.x.com/1.1/' },
);
console.log('Media is ready:', mediaStatus.processing_info.state === 'succeeded');
```
Expand All @@ -360,6 +360,6 @@ But if this doesn't work (fe Twitter error of invalid body format), you can buil
await client.v1.post(
'media/upload.json',
{ command: 'APPEND', media_id: '20', segment_index: '0', media: fs.readFileSync('./media.jpg') },
{ prefix: 'https://upload.twitter.com/1.1/', forceBodyMode: 'form-data' },
{ prefix: 'https://upload.x.com/1.1/', forceBodyMode: 'form-data' },
);
```
2 changes: 1 addition & 1 deletion doc/http-wrappers.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Sometimes, you need to customize request settings (API prefix, body mode, respon
```ts
// [prefix]
// Customize API prefix (prefix that will be prepended to URL in first argument)
client.v1.post('media/upload.json', { media: Buffer.alloc(1024) }, { prefix: 'https://upload.twitter.com/1.1/' })
client.v1.post('media/upload.json', { media: Buffer.alloc(1024) }, { prefix: 'https://upload.x.com/1.1/' })

// [forceBodyMode]
// Customize body mode (if automatic body detection don't work)
Expand Down
12 changes: 6 additions & 6 deletions doc/streaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Method: **`v1.filterStream`**.

Endpoint: `statuses/filter.json`.

Reference: https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/api-reference/post-statuses-filter
Reference: https://developer.x.com/en/docs/twitter-api/v1/tweets/filter-realtime/api-reference/post-statuses-filter

Level: **Read-only**.

Expand All @@ -131,7 +131,7 @@ Method: **`v1.sampleStream`**.

Endpoint: `statuses/sample.json`.

Reference: https://developer.twitter.com/en/docs/twitter-api/v1/tweets/sample-realtime/api-reference/get-statuses-sample
Reference: https://developer.x.com/en/docs/twitter-api/v1/tweets/sample-realtime/api-reference/get-statuses-sample

Level: **Read-only**.

Expand All @@ -153,7 +153,7 @@ Method: **`v2.searchStream`**.

Endpoint: `tweets/search/stream`.

Reference: https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream
Reference: https://developer.x.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream

Level: **Read-only**.

Expand All @@ -171,7 +171,7 @@ Method: **`v2.streamRules`**.

Endpoint: `tweets/search/stream/rules (GET)`.

Reference: https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream-rules
Reference: https://developer.x.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/get-tweets-search-stream-rules

Level: **Read-only**.

Expand All @@ -192,7 +192,7 @@ Method: **`v2.updateStreamRules`**.

Endpoint: `tweets/search/stream/rules (POST)`.

Reference: https://developer.twitter.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/post-tweets-search-stream-rules
Reference: https://developer.x.com/en/docs/twitter-api/tweets/filtered-stream/api-reference/post-tweets-search-stream-rules

Level: **Read-write**.

Expand Down Expand Up @@ -224,7 +224,7 @@ Method: **`v2.sampleStream`**.

Endpoint: `tweets/sample/stream`.

Reference: https://developer.twitter.com/en/docs/twitter-api/tweets/sampled-stream/api-reference/get-tweets-sample-stream
Reference: https://developer.x.com/en/docs/twitter-api/tweets/sampled-stream/api-reference/get-tweets-sample-stream

Level: **Read-only**.

Expand Down
2 changes: 1 addition & 1 deletion doc/v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ Returns a single Tweet, specified by either a Tweet web URL or the Tweet ID, in

**Method**: `.oembedTweet()`

**Endpoint**: `oembed` (publish.twitter.com)
**Endpoint**: `oembed` (publish.x.com)

**Right level**: `Read-only`

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"prepublish": "npm run build"
},
"repository": "github:plhery/node-twitter-api-v2",
"author": "Paul-Louis Hery <[email protected]> (https://twitter.com/plhery)",
"author": "Paul-Louis Hery <[email protected]> (https://x.com/plhery)",
"license": "Apache-2.0",
"files": [
"dist"
Expand All @@ -56,4 +56,4 @@
"bugs": {
"url": "https://github.com/plhery/node-twitter-api/issues"
}
}
}
2 changes: 1 addition & 1 deletion src/client-mixins/request-handler.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class RequestHandlerHelper<T> {
}

protected isFormEncodedEndpoint() {
return this.requestData.url.href.startsWith('https://api.twitter.com/oauth/');
return this.requestData.url.href.startsWith('https://api.x.com/oauth/');
}

/* Error helpers */
Expand Down
4 changes: 2 additions & 2 deletions src/client-mixins/request-param.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class RequestParamHelpers {
return 'json';
}

if (url.hostname === 'upload.twitter.com') {
if (url.hostname === 'upload.x.com') {
if (url.pathname === '/1.1/media/upload.json') {
return 'form-data';
}
Expand Down Expand Up @@ -165,7 +165,7 @@ export class RequestParamHelpers {

/**
* Replace URL parameters available in pathname, like `:id`, with data given in `parameters`:
* `https://twitter.com/:id.json` + `{ id: '20' }` => `https://twitter.com/20.json`
* `https://x.com/:id.json` + `{ id: '20' }` => `https://x.com/20.json`
*/
static applyRequestParametersToUrl(url: URL, parameters: TRequestQuery) {
url.pathname = url.pathname.replace(/:([A-Z_-]+)/ig, (fullMatch, paramName: string) => {
Expand Down
18 changes: 9 additions & 9 deletions src/client/readonly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ export default class TwitterApiReadOnly extends TwitterApiBase {
}: Partial<RequestTokenArgs> = {}
) {
const oauthResult = await this.post<RequestTokenResult>(
'https://api.twitter.com/oauth/request_token',
'https://api.x.com/oauth/request_token',
{ oauth_callback, x_auth_access_type: authAccessType }
);
let url = `https://api.twitter.com/oauth/${linkMode}?oauth_token=${encodeURIComponent(oauthResult.oauth_token)}`;
let url = `https://api.x.com/oauth/${linkMode}?oauth_token=${encodeURIComponent(oauthResult.oauth_token)}`;

if (forceLogin !== undefined) {
url += `&force_login=${encodeURIComponent(forceLogin)}`;
Expand Down Expand Up @@ -147,7 +147,7 @@ export default class TwitterApiReadOnly extends TwitterApiBase {
throw new Error('You must setup TwitterApi instance with consumer keys to accept OAuth 1.0 login');

const oauth_result = await this.post<AccessTokenResult>(
'https://api.twitter.com/oauth/access_token',
'https://api.x.com/oauth/access_token',
{ oauth_token: tokens.accessToken, oauth_verifier }
);

Expand Down Expand Up @@ -186,7 +186,7 @@ export default class TwitterApiReadOnly extends TwitterApiBase {

// Create a client with Basic authentication
const basicClient = new TwitterApi({ username: tokens.appKey, password: tokens.appSecret }, this._requestMaker.clientSettings);
const res = await basicClient.post<BearerTokenResult>('https://api.twitter.com/oauth2/token', { grant_type: 'client_credentials' });
const res = await basicClient.post<BearerTokenResult>('https://api.x.com/oauth2/token', { grant_type: 'client_credentials' });

// New object with Bearer token
return new TwitterApi(res.access_token, this._requestMaker.clientSettings);
Expand All @@ -200,7 +200,7 @@ export default class TwitterApiReadOnly extends TwitterApiBase {
* - **You can only use v2 API endpoints with this authentication method.**
* - **You need to specify which scope you want to have when you create your auth link. Make sure it matches your needs.**
*
* See https://developer.twitter.com/en/docs/authentication/oauth-2-0/user-access-token for details.
* See https://developer.x.com/en/docs/authentication/oauth-2-0/user-access-token for details.
*
* ```ts
* // Instantiate TwitterApi with client ID
Expand Down Expand Up @@ -230,7 +230,7 @@ export default class TwitterApiReadOnly extends TwitterApiBase {
const rawScope = options.scope ?? '';
const scope = Array.isArray(rawScope) ? rawScope.join(' ') : rawScope;

const url = new URL('https://twitter.com/i/oauth2/authorize');
const url = new URL('https://x.com/i/oauth2/authorize');
const query = {
response_type: 'code',
client_id: this._requestMaker.clientId,
Expand Down Expand Up @@ -293,7 +293,7 @@ export default class TwitterApiReadOnly extends TwitterApiBase {
);
}

const accessTokenResult = await this.post<AccessOAuth2TokenResult>('https://api.twitter.com/2/oauth2/token', {
const accessTokenResult = await this.post<AccessOAuth2TokenResult>('https://api.x.com/2/oauth2/token', {
code,
code_verifier: codeVerifier,
redirect_uri: redirectUri,
Expand Down Expand Up @@ -323,7 +323,7 @@ export default class TwitterApiReadOnly extends TwitterApiBase {
);
}

const accessTokenResult = await this.post<AccessOAuth2TokenResult>('https://api.twitter.com/2/oauth2/token', {
const accessTokenResult = await this.post<AccessOAuth2TokenResult>('https://api.x.com/2/oauth2/token', {
refresh_token: refreshToken,
grant_type: 'refresh_token',
client_id: this._requestMaker.clientId,
Expand All @@ -347,7 +347,7 @@ export default class TwitterApiReadOnly extends TwitterApiBase {
);
}

return await this.post<void>('https://api.twitter.com/2/oauth2/revoke', {
return await this.post<void>('https://api.x.com/2/oauth2/revoke', {
client_id: this._requestMaker.clientId,
client_secret: this._requestMaker.clientSecret,
token,
Expand Down
10 changes: 5 additions & 5 deletions src/globals.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const API_V2_PREFIX = 'https://api.twitter.com/2/';
export const API_V2_LABS_PREFIX = 'https://api.twitter.com/labs/2/';
export const API_V1_1_PREFIX = 'https://api.twitter.com/1.1/';
export const API_V1_1_UPLOAD_PREFIX = 'https://upload.twitter.com/1.1/';
export const API_V1_1_STREAM_PREFIX = 'https://stream.twitter.com/1.1/';
export const API_V2_PREFIX = 'https://api.x.com/2/';
export const API_V2_LABS_PREFIX = 'https://api.x.com/labs/2/';
export const API_V1_1_PREFIX = 'https://api.x.com/1.1/';
export const API_V1_1_UPLOAD_PREFIX = 'https://upload.x.com/1.1/';
export const API_V1_1_STREAM_PREFIX = 'https://stream.x.com/1.1/';
26 changes: 13 additions & 13 deletions src/types/errors.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,23 +338,23 @@ export enum EApiV1ErrorCode {

export enum EApiV2ErrorCode {
// Request errors
InvalidRequest = 'https://api.twitter.com/2/problems/invalid-request',
ClientForbidden = 'https://api.twitter.com/2/problems/client-forbidden',
UnsupportedAuthentication = 'https://api.twitter.com/2/problems/unsupported-authentication',
InvalidRequest = 'https://developer.x.com/en/support/x-api/error-troubleshooting#invalid-request',
ClientForbidden = 'https://developer.x.com/en/support/x-api/error-troubleshooting#client-forbidden',
UnsupportedAuthentication = 'https://developer.x.com/en/support/x-api/error-troubleshooting#unsupported-authentication',

// Stream rules errors
InvalidRules = 'https://api.twitter.com/2/problems/invalid-rules',
TooManyRules = 'https://api.twitter.com/2/problems/rule-cap',
DuplicatedRules = 'https://api.twitter.com/2/problems/duplicate-rules',
InvalidRules = 'https://developer.x.com/en/support/x-api/error-troubleshooting#invalid-rules',
TooManyRules = 'https://developer.x.com/en/support/x-api/error-troubleshooting#rule-cap',
DuplicatedRules = 'https://developer.x.com/en/support/x-api/error-troubleshooting#duplicate-rules',

// Twitter errors
RateLimitExceeded = 'https://api.twitter.com/2/problems/usage-capped',
ConnectionError = 'https://api.twitter.com/2/problems/streaming-connection',
ClientDisconnected = 'https://api.twitter.com/2/problems/client-disconnected',
TwitterDisconnectedYou = 'https://api.twitter.com/2/problems/operational-disconnect',
RateLimitExceeded = 'https://developer.x.com/en/support/x-api/error-troubleshooting#usage-capped',
ConnectionError = 'https://developer.x.com/en/support/x-api/error-troubleshooting#streaming-connection',
ClientDisconnected = 'https://developer.x.com/en/support/x-api/error-troubleshooting#client-disconnected',
TwitterDisconnectedYou = 'https://developer.x.com/en/support/x-api/error-troubleshooting#operational-disconnect',

// Resource errors
ResourceNotFound = 'https://api.twitter.com/2/problems/resource-not-found',
ResourceUnauthorized = 'https://api.twitter.com/2/problems/not-authorized-for-resource',
DisallowedResource = 'https://api.twitter.com/2/problems/disallowed-resource',
ResourceNotFound = 'https://developer.x.com/en/support/x-api/error-troubleshooting#resource-not-found',
ResourceUnauthorized = 'https://developer.x.com/en/support/x-api/error-troubleshooting#not-authorized-for-resource',
DisallowedResource = 'https://developer.x.com/en/support/x-api/error-troubleshooting#disallowed-resource',
}
2 changes: 1 addition & 1 deletion src/types/v1/streaming.v1.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface AskTweetStreamV1Params {
}

/**
* See https://developer.twitter.com/en/docs/twitter-api/v1/tweets/filter-realtime/guides/basic-stream-parameters
* See https://developer.x.com/en/docs/twitter-api/v1/tweets/filter-realtime/guides/basic-stream-parameters
* for detailed documentation.
*/
export interface FilterStreamV1Params extends AskTweetStreamV1Params {
Expand Down
Loading

0 comments on commit 8dc65e6

Please sign in to comment.