https://github.com/cmdcolin/twitter_fractal_bot
Posts random images of fractals to twitter
https://github.com/cmdcolin/twitter_fractal_bot
Last synced: 22 days ago
JSON representation
Posts random images of fractals to twitter
- Host: GitHub
- URL: https://github.com/cmdcolin/twitter_fractal_bot
- Owner: cmdcolin
- Created: 2022-08-22T15:02:49.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-15T20:19:54.000Z (almost 4 years ago)
- Last Synced: 2025-01-15T08:43:16.452Z (over 1 year ago)
- Language: TypeScript
- Size: 899 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# twitter_fractal_bot
Posts images of fractals to twitter at https://twitter.com/chaosbot80

Example image
## How to make your own bot with this code
Create a .env file with contents like this
```
API_KEY="xxxxxxxxxxxxxxxxxxxxxxxxx"
API_SECRET="yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
ACCESS_TOKEN="aaaaaaaaaaaaaaaaaaa-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
ACCESS_TOKEN_SECRET="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
```
Note 1: The format of these keys is approximately the length of the things that
are given to you by twitter. The ACCESS_TOKEN as
aaaaaaaaaaaaaaaaaaa-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa is just how it's given to
you, it's not two different things
Note 2: The API key is sometimes referred to as "consumer key" in other (older)
twitter API references.
Note 3: You cannot use the Bearer token to post tweets. Also, there is the
"official twitter API SDK" but this repo does not use it...I wasn't able to
figure it out initially but now that I understand OAuth a bit better it may be
possible to try again to use it
https://github.com/twitterdev/twitter-api-typescript-sdk

See this blogpost for a couple added details
https://cmdcolin.github.io/posts/2022-08-26-twitterbot
Figure showing where to get the API key+API secret (box 1) and access token+access secret (box 2)
## Usage
Run `yarn post` to make a new post to twitter with a random Figure
Run `yarn gen` to just make a new random image
## Other
My first twitter bot! I struggled with the code for authenticating properly for
a little while (many references use a OAuth flow that requires a user with a
web browser to login or something like this, and there is a lot of vocabulary
to get used to about OAuth, API key, consumer key, access key, OAuth 1 vs 2,
twitter API 1 vs 2, etc.) so this codebase may be a reasonably nice and simple
example of "how to make a twitter bot 2022". See [src/bot.ts](src/bot.ts) for
the twitter bot in particular, it just uploads an image generated by
[src/index.ts](src/index.ts). This codebase uses twitter API v1 to upload the
image, and twitter API v2 to post the image.