Rails for Beginners Part 33: Twitter API Discussion
I may have missed something during the initial configuration but I had only set read permissions for the app so the .update(body) method was obvisously returning Twitter::Error::Unauthorized (Read-only application cannot POST.). If someone encouters the same issue, go to https://developer.twitter.com/en/portal/dashboard, find your app, in "settings" switch the app permissions to "Read, Write, and Direct Messages", then in "keys and tokens", revoke access token & secret for your test account and then disconnect and reconnect the account through your rails app running locally.
I just ran into this as well, twitter apps are new to me, though I have plans to use them.
You saved me! I ran into as well and was scratching my head.
Edit Actually it looks like I am having a different problem. I am getting Unauthorized (Could not authenticate you) https://rdoc.info/gems/twitter/Twitter/Error#Unauthorized-constant back when trying to use the twitter gem. So I am doing something wrong with saving out credentials or configuring the client.
Hi Cris, my problem is: If I want to disconect it is giving me an error.
ActiveRecord::InvalidForeignKey in TwitterAccountsController#destroy
SQLite3::ConstraintException: FOREIGN KEY constraint failed
I think it is for the update tweet_id: tweet_id
@David, check whether there's a comma at the end of
I had the commas at the end, because of copy paste so I was getting Unauthorized error.
@Adalberto, @Konstantinos Gallis awnser your question in another video. Just do:
Checkout the video 39 (https://gorails.com/episodes/rails-for-beginners-part-39-dependent-destroy-model-associations)
Go in the file twitter_account.rb and replace:
has_many :tweets, dependent: :destroy
If you get
Twitter::Error::Unauthorized (Read-only application cannot POST.)
Could not authorize you
Go to twitter developer setting and under App permissions enable Read, Write and Direct Messages. It was on Read Only for me before.
And then regenerate all the keys/tokens + update them again in your app.
Also helps to restart the servers/console again. Fixed the problem for me.