Retweet Tweets with a special Hashtag

Hey there,
I´m getting more and more into the n8n world and I guess I´m a little bit addicted to this. But as often, I come across some questions I can´t solve myself. Maybe someone can help me.

What´s my goal?
I want to retweet tweets from other Users with a special hashtag #stuttgarttype

What have I done so far?

  1. Cronjob, to execute the workflow every hour
  2. Twitter node: Search for tweets with the hashtag #stuttgarttype (limit: 50)
  3. Twitter node: Retweet the result

At point 3 I don´t know what to do. I have the hashtag results from node 2. Ok. But how can I retweet the newest tweet(s) that haven´t been tweeted already? Sorry, I hope I didn´t explain it too complicated.

Here is my workflow so far:

Thanks for your help and have a nice evening.

Hi @Floyd, I hope you’re well? It seems on your second Twitter node you are referencing the id value of the tweets you have previously searched. Twitter would, however, want the id_str value. So if you simply update your expression from {{$node["Twitter_Search1"].json["id"]}} to something like {{$json["id_str"]}}, Twitter should find the Tweet you’re looking for and let you retweet it.

Edit: Keep in mind that Twitter will only let you retweet each Tweet once though. So if you try to retweet Retweets of a Tweet you have already retweeted you might get another error.

So you might want to either ignore that or add a bit of filtering for that, e.g. like so (I’m not 100% sure about this one as I am not super familiar with Twitter’s behaviour, but it seems to have worked for me):

Example Workflow
1 Like

Hey @MutedJam, thanks for clearing things up. I guess I understand it a little bit better now :wink: The workflow works, but there is one more thing I try to solve. How can I prevent, that my own tweets with the hashtag #stuttgarttype will be retweetet.

One simple workaround, that comes to my mind: the usage of two hashtags. One for my own tweets, e.g. #stuttgart_type and one for the retweets, e.g. #stuttgarttype.

But maybe there is a solution that it is possible to prevent my own tweets from being retweetet. Do you see a solution? Can you give me a little help, please?

Thank you so much for your help so far.

So the IF node in my example workflow above will already check whether the retweeted_status field provided by Twitter is empty (to make sure a Tweet is an original Tweet and not a Retweet).

You could add a separate condition to this node checking the user’s name doesn’t match your name:

image

The expression used in the Value 1 field above is {{$json["user"]["screen_name"]}}.

The below example workflow searches for Tweets with n8n and then filters out those that are Retweets and those that are from @n8n_io:

Example Workflow

Hope this helps :slight_smile:

1 Like

Wow @MutedJam, thanks a lot for your help. I have to play a little bit around with the IF node. Seems to be a node I would need often :wink:

I really appreciate your help and will no spend the afternoon with playing around with different nodes. I have to learn a lot :slight_smile:

Thank you!

1 Like

You are most welcome! Let me know if you get stuck somewhere.

2 Likes