All threads / Rails for Beginners Part 33: Twitter API Discussion

Ask A Question

Notifications

You’re not receiving notifications from this thread.

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
Rails.application.credentials.dig(:twitter, :api_key)
and
Rails.application.credentials.dig(:twitter, :api_secret)

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

with:
has_many :tweets, dependent: :destroy

mannn thanks so much u saved me

Reply

If you get

Twitter::Error::Unauthorized (Read-only application cannot POST.)

Or

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.

Reply
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 48,387+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.