Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Commit

Permalink
Can't use app-only, since it's read-only on Twitter
Browse files Browse the repository at this point in the history
  • Loading branch information
derkweijers committed Aug 23, 2023
1 parent 866dba9 commit 6cb42ab
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
AMQP_URL=
DEBUG=
API_KEY=
API_SECRET=
ACCESS_TOKEN=
ACCESS_TOKEN_SECRET=
DB_LOCATION=
SENTRY_DSN=
BEARER_TOKEN=
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "snapi-twitter-bot",
"version": "1.6.0",
"version": "1.6.1",
"description": "The official Twitter bot for the Spaceflight News API.",
"main": "app.js",
"scripts": {
Expand Down
16 changes: 8 additions & 8 deletions src/utils/TwitterClientV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {Tweet} from "../entity/Tweet";
class TwitterClientV2 {
private client: TwitterApiReadWrite

constructor(bearerToken?: string) {
// Proccess.env.BEARER_TOKEN can be empty, so we need to check for that.
if (!bearerToken) {
throw new Error("No bearer token provided");
}

this.client = new TwitterApi(bearerToken).readWrite;
constructor(apiKey: string, apiSecret: string, accessToken: string, accessTokenSecret: string) {
this.client = new TwitterApi({
appKey: apiKey,
appSecret: apiSecret,
accessToken: accessToken,
accessSecret: accessTokenSecret,
}).readWrite;
}

async sendTweet(tweet: Tweet): Promise<TweetV2PostTweetResult | void> {
Expand All @@ -24,4 +24,4 @@ class TwitterClientV2 {
}
}

export const twitterClientV2: TwitterClientV2 = new TwitterClientV2(process.env.BEARER_TOKEN);
export const twitterClientV2: TwitterClientV2 = new TwitterClientV2(process.env.API_KEY!, process.env.API_SECRET!, process.env.ACCESS_TOKEN!, process.env.ACCESS_TOKEN_SECRET!);

0 comments on commit 6cb42ab

Please sign in to comment.