Skip to content

Enable Huginn Twitter integration

Huginn comes with a number of Twitter agents, but before they can be used you need to authenticate them. That process requires multiple steps, and they are not well documented.

The basics are described on the "Configuring OAuth applications" Wiki page.

For the Twitter integration one must know that you are using a single Twitter app for all users, but every Huginn user can (and should) have this app authenticated against their own Twitter account. Therefore if you want to use multiple Twitter accounts in Huginn, you need multiple Huginn users.


The steps required for me to get this working:

Create a Twitter App

With your Twitter account, login into the Twitter Developer site. Create a new app, fill out all the necessary details.

Very important: you have to specify two Callback URLs!

  1. https://<your Huginn site>/auth/twitter
  2. https://<your Huginn site>/auth/twitter/callback

The two callbacks need to be in that order, otherwise the authentication will not work.

Write down the Consumer API key & secret, and the Access token & secret. This needs to be added to Huginn in the next step.

Add the Twitter App as Service in Huginn

Connect to your Huginn instance using ssh, and edit the .env file. You need to add/enable two lines:


In my case the entire installation is deployed using Ansible, and I'm using the lineinfile module to update the file:

- name: Set database variables
    twitter_api_key:  "{{ lookup('file', playbook_dir + '/credentials/huginn/twitter-api-key.txt') }}"
    twitter_api_secret:  "{{ lookup('file', playbook_dir + '/credentials/huginn/twitter-api-secret.txt') }}"

- name: Update .env
    dest: "/home/huginn/huginn/.env"
    regexp: "{{ item.regexp }}"
    line: "{{ item.line }}"
    state: "{{ item.state }}"
    - { name: 'TWITTER_OAUTH_KEY', regexp: '^#* *TWITTER_OAUTH_KEY', line: 'TWITTER_OAUTH_KEY={{ twitter_api_key }}', state: present }
    - { name: 'TWITTER_OAUTH_SECRET', regexp: '^#* *TWITTER_OAUTH_SECRET', line: 'TWITTER_OAUTH_SECRET={{ twitter_api_secret }}', state: present }
    label: "{{ }}"
    - restart huginn

After changing the .env file, Huginn must be restarted.

Authenticate the Twitter App as user in Huginn

If there are no errors in the log after the restart, login into Huginn using a regular user. Click on "Services", and then on "Authenticate with Twitter".

This will redirect to the Twitter website, you have to login there with your credentials, and authenticate the app for this account. Afterwards Twitter will redirect back to the Huginn installation, using the two callback links which are specified in the app settings.

Use Twitter Agents

Now that the app is authenticated, Twitter agents can be added. See other blog posts and the documentation for this.

If you want to use multiple Twitter accounts, create multiple Huginn accounts. Each account can use it's own Twitter credentials.



No Trackbacks


Display comments as Linear | Threaded

No comments

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.
To leave a comment you must approve it via e-mail, which will be sent to your address after submission.
Form options