I am having a hard time trying to post tweets usin...
# cfml-general
h
I am having a hard time trying to post tweets using ColdFusion with the X (formerly Twitter) Rest API. I found some examples, but they are all very old and use the old v1.1 API. I checked the code from @Adam Cameron using Twitter4J (https://blog.adamcameron.me/2012/10/sending-tweets-via-coldfusion-via.html), which unfortunately was not working. I modified it to:
twitter = createObject("java", "twitter4j.Twitter").newBuilder()
.oAuthConsumer("CONSUMER", "TOKEN")
.oAuthAccessToken("TOKEN", "SECRET")
.build();
status = twitter.v1().tweets().updateStatus("Hello World");
Which will give me "403:The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following). message - You currently have access to a subset of Twitter API v2 endpoints and limited v1.1 endpoints (e.g. media post, oauth) 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/portal/product code - 453" Also monkehTweets (@monkeh.me) and so on had a similar issue:
<cfset monkehTweet = new <http://monkehTweets.com|monkehTweets.com>.coldfumonkeh.monkehTweet(
consumerKey			=	'...',
consumerSecret		=	'...',
oauthToken			=	'...',
oauthTokenSecret	=	'...',
userAccountName		=	'@ApiContens',
parseResults		=	true,
timeout = 250
)>
<cfset dataReturn = monkehTweet.postUpdate('Nothing to see here.. just testing something. Move along.')>
<cfdump var="#dataReturn#">
Result: You currently have access to a subset of Twitter API v2 endpoints and limited v1.1 endpoints (e.g. media post, oauth) 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/portal/produc I would like to post a simple tweet e.g.
curl --location '<https://api.twitter.com/2/tweets>' \
--data '{
"text": "Hello World!"
}' --header 'Authorization: Bearer {%Bearer Token%}'
But this doesn't work with the bearer token from the developers portal. Any idea on how to set the correct Authorization? Thanks a lot!
r
I'm pretty sure Adam's code and monkehTweet is working correctly. X has limited access to the free tier to the point that it's pretty much unusable.
👍 1
✔️ 1
h
I guess the problem is that Twitter4J and monkehTweet both use the v1.1 API - which is very limited for the free tier. Posts should work with /2/tweets but I am struggling with the Authorization Header
Forgot to mention that the code from @Adam Cameron sure worked with the JAR version he used at that time, but I was using the latest version and there ConfigurationBuilder didn't exist anymore. But I found the solution with newBuilder(), which worked fine.
a
@harryk if you could come up with a gist or something that shows how to do it "these days" it would be cool, and if poss I'd update that article with a warning @ the top saying "yeah nah, this dun't work any more: try this". But also NP at all if you can't be arsed 😉 I def can't be arsed doing it myself 😄
q
Didn't they nerf most of the v2 APIs too, unless you were an "enterprise developer?" (and even then, they charge per tweet you post).. From what I remember, the changes were that you could read your own tweets, and they rate limited you on tweets from other folks's timelines to the point it was useless unless you had that enterprise dev key...
@quetwo I found this information https://twitter.com/XDevelopers/status/1621026986784337922?s=20&amp;t=O2S-kqvzREMlmNE_4BFNCg "Starting February 9, we will no longer support free access to the Twitter API, both v2 and v1.1. A paid basic tier will be available instead" Ok, so it seems that even v2 tweets posts are not working anymore - I wasn't sure as I ws reading a lot of conflicting infos
q
It's pretty much it. Unless you have a paid account, twitter APIs are pretty much toast.
👍 1
a
Cheers @harryk (and @quetwo). Gonna replicate a version of what you say here on that blog article. I don't want ppl wasting their time with old code wot dun't work.
👍 1