An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# twitter_fractal_bot

Posts images of fractals to twitter at https://twitter.com/chaosbot80

![](img/2.jpeg)

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

![](img/devpanel.png)

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.