0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

公式のTwitter SDKを使ってTweetを取得するメモ (Twitter API v2)

Last updated at Posted at 2022-10-15

公式SDKのサンプルなどを漁ってもイマイチぱっと動かせるものがなかったので動かせたものメモ

Bearer Token

スクリーンショット 2022-10-16 1.08.45.png

Bearer Tokenを取得しておく。

SDKインストール

$ npm i twitter-api-sdk

ツイート取得

TypeScript SDKですがJavaScript(Node.js)で利用してます。

const {Client} = require('twitter-api-sdk');
const client = new Client(`<Bearer Tokenを記載>`);

const userName = "n0bisuke";

(async () => {
    const { data } = await client.users.findUserByUsername(userName);
    const tweets = client.tweets.usersIdTweets(data.id);
    for await (const page of tweets) {
    	console.log(page.data);
    }
})();

以下の記事を参考にさせてもらいました。

参考: https://shinshin86.hateblo.jp/entry/2022/07/22/115511

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?