6
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Ruby の twitter gem で Twitter API の確認をする

Last updated at Posted at 2023-04-21

App で API v2 を使えるかどうか知りたいときがある

前提

  • twitter app が standalone app だと API v1.1対応
  • app が project app だと API v1.1 / v2 対応

v2 対応じゃない

> require 'twitter'
> client = Twitter::REST::Client.new(
  access_token: "...",
  access_token_secret: "...",
  consumer_key: "...",
  consumer_secret: "...",
)
> client.send(:perform_get, '/1.1/account/verify_credentials.json')[:screen_name]
"..."
> client.send(:perform_get, '/2/users/me')
lib/twitter/rest/request.rb:97:in `fail_or_return_response_body': Twitter::Error::Forbidden (Twitter::Error::Forbidden)

v2 対応

> require 'twitter'
> client = Twitter::REST::Client.new(
  access_token: "...",
  access_token_secret: "...",
  consumer_key: "...",
  consumer_secret: "...",
)
> client.send(:perform_get, '/1.1/account/verify_credentials.json')[:screen_name]
"..."
> client.send(:perform_get, '/2/users/me')[:data][:username]
"..."

まとめ

リクエストすればいいんだけど,設定がアプリに入っているので,
コンソールでやった方がいいとかの場合には使えるかも?

6
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?