Search code examples
c#twittertweetinvi

Authenticate twitter bot with static secrets?


My plan:

I am writing a bot, that will send some tweets every now and then using the library tweetinvi (https://github.com/linvi/tweetinvi).

The bot is currently using the access token and secret I generated in my developer console.

The issue:

The bot will send the tweets using my personal account now. That's why I created a new secondary account, that should be used for the tweets in the future.

But how can I authenticate the bot now?

  1. The new account is not a developer account and I don't see any option to generate an access token and secret in the account settings.

  2. Further more I don't think the usual oauth "click on the twitter icon and login to twitter" sign in is the right choice for my bot, because I don't have a website or browser session, just a program that runs wherever.

Can't I just create a some static sort of access token and a secret for my secondary account?

What would you suggest me to do, if that is not possible?


Solution

  • Yes, you can create an access token and secret for your secondary account. The standard way to do this would be to implement sign-in with Twitter in an app, which would require a web backend.

    There are a couple of alternative options:

    1. You can use twurl, which is a Twitter-provided command line tool. You’ll need to have Ruby installed, and then install twurl. Using twurl you can run

    twurl authorize --consumer-key [your API token] --consumer-secret [your API secret]

    This will then provide a URL you should open in your browser. Authenticate this to your secondary account and type the PIN into your terminal. The account token and secret will be placed in a hidden file called .twurlrc in your home directory, and you can use them for your bot in the same way you’re currently using your main account tokens.

    1. You can use another utility called tw-oob-oauth-cli to do the same thing. This is a bit easier as you don’t need to install Ruby, and can just download a Windows binary. You’ll want to rename the binary with a .exe extension.

    tw-oob-oauth.exe --key [your API token] --secret [your API secret]

    This will output the account token and secret on the terminal after you’ve been through the web flow.