Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node-red-node-twitter API V1.1 problem to tweet #1000

Open
ArfyFR opened this issue May 26, 2023 · 4 comments
Open

node-red-node-twitter API V1.1 problem to tweet #1000

ArfyFR opened this issue May 26, 2023 · 4 comments

Comments

@ArfyFR
Copy link

ArfyFR commented May 26, 2023

Hi

Trying to send a tweet I get the error
"You currently have access to Twitter API v2 endpoints and limited v1.1 endpoints only. If you need access to this endpoint, you may need a different access level. You can learn more here: https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve"

According to
https://twittercommunity.com/t/453-you-currently-have-essential-access-which-includes-access-to-twitter-api-v2-endpoints-only-if-you-need-access-to-this-endpoint-you-ll-need-to-apply-for-elevated-access-via-the-developer-portal-you-can-learn-more-here-https-developer-twitter-co/193001
it seems that API v1.1 can only be used to send Media now

To tweet: api V2

But in code the 1.1 seems to be used to tweet (with or without media)
node.twitterConfig.post("https://api.twitter.com/1.1/statuses/update.json",{},params).then(function(result) {
in node-red-node-twitter/27-twitter.js

@ArfyFR
Copy link
Author

ArfyFR commented Jun 11, 2023

Sorry for disturbing. I found your names on https://flows.nodered.org/node/node-red-node-twitter
@dceejay @knolleary do you know if there is a plan to correct it ?

@b-neufeld
Copy link

I don't have the skills to propose a fix but I managed to brute-force a workaround to keep Node-RED tweeting (sort of).

Here are some details I hope might help others patch up their tweeting applications.

First, I have Node-RED running in a Docker container. So, when the container is initialized I install tweepy with an exec block:
image

The command it runs is curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python3 get-pip.py && export PATH="/usr/src/node-red/.local/bin/:$PATH" && pip install tweepy which grabs a .py installer script for pip, executes it, adds the pip directory to $PATH, and finally installs tweepy (via pip).

My tweeting flow looks like this:
image

My Twitter bot tweets media that it grabs via the http request block. To get this to work, I can no longer pass a binary object to a Twitter block, I have to write it to a file with the Write File node. The Twitter Enable gate is logic that turns off tweets if data fails validation (not relevant to this workaround).

Finally the exec node calls cd / && cd data && python3 tweet_daily.py which executes tweet_daily.py in my data directory (which is mounted outside my docker container).

This is the tweepy script to tweet with media:

import tweepy
from tweepy import API, Client

# consumer key
# consumer secret
# access token
# access secret
auth = tweepy.OAuth1UserHandler(
   "asdf",
   "asdf",
   "asdf",
   "asdf"
)

client = tweepy.Client(
   consumer_key="asdf",
   consumer_secret="asdf",
   access_token="asdf",
   access_token_secret="asdf",
)

api = tweepy.API(auth)

# assume media is in same dir as python script
media = api.media_upload(filename="image_filename.png")
print("MEDIA: ", media)

tweet = client.create_tweet(text="Tweeting is fun and not super easy!", media_ids= 
[media.media_id_string])
print("TWEET: ", tweet)

And this is what it looks like to tweet without media:

import tweepy
from tweepy import API, Client

client = tweepy.Client(
   consumer_key="asdf",
   consumer_secret="asdf",
   access_token="asdf",
   access_token_secret="asdf",
)

tweet = client.create_tweet(text="Tweeting is fun and not super easy!")
print("TWEET: ", tweet)

Hope this helps someone else 👍

@langfeld
Copy link

langfeld commented Jul 9, 2023

Hope this helps someone else +1

Thank you very much, your detailed explanation has indeed helped me a lot 👍

@8666
Copy link

8666 commented Aug 14, 2023

Is there are plan for a real fix? I can not tweet anything from my node-red bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants