Skip to main content

Twitter

With this integration you can perform actions on Twitter from Js.

Credential configuration

To configure this credential you need the Bearer token from one Twitter app. You can find it on Twitter developer portal, selecting the app (or creating one) and go to Keys and tokens tab. You'll find the bearer token inside Authentication tokens section.

Optionally you can set in the JSON field some request options which are common to all requests.

Here you have an example of a filled credential configuration form in YepCode:

Twitter snippets available in editor

tip

Explore the full Twitter API docs in: https://developer.twitter.com/en/docs/twitter-api

note

The title is the triggering text for YepCode to autocomplete the script

Integration

New integration from credential
const twitter = yepcode.integration.twitter('credential-slug');
New integration from plain authentication data
const { Client } = require("twitter-api-sdk");

const twitter = new Client('bearer-token')

Search recent tweets

Search recent tweets
const searchRecentTweetsResponse = await twitter.tweets.tweetsRecentSearch({
query: "the-search-query", // Example: from:yepcode_io
"tweet.fields": ["author_id", "text"],
expansions: ["author_id"],
});

searchRecentTweetsResponse.data.forEach(console.log);

Get user tweets

Get user tweets
const userTweetsResponse = await twitter.tweets.usersIdTweets("user-id");

userTweetsResponse.data.forEach(console.log);

Get tweet by id

Get tweet by id
const getTweetResponse = await twitter.tweets.findTweetById("tweet-id");

console.log(getTweetResponse.data);

Find users by username

Find users by username
const findUsersByUsernameResponse = await twitter.users.findUsersByUsername({
usernames: ["username1"],
"user.fields": "id,name,username,description,verified",
});

findUsersByUsernameResponse.data.forEach(console.log);

Find users by id

Find users by id
const findUsersByIdResponse = await twitter.users.findUsersById({
ids: ["id1"],
"user.fields": "id,name,username,description,verified",
});

findUsersByIdResponse.data.forEach(console.log);

Get followers

Get followers
const getFollowersResponse = await twitter.users.usersIdFollowers("user-id");

getFollowersResponse.data.forEach(console.log)