t_wの輪郭

TwitterのDeveloper Portalのプロジェクトページで、「Do you need Elevated access for your Project?」右横の「Apply」ボタンを押す。

「How will you use the Twitter API or Twitter Data?」ページでAPIの利用用途を書く

文例:
In your words

I will do:

  • Tweet the website's update and PV achievement automatically as my Twitter account with POST statuses/update.
  • Analyze the words weight on Twitter for writing the website's post with Search Tweets.

Are you planning to analyze Twitter data? → Yes
Please describe how you will analyze Twitter data including any analysis of Tweets or Twitter users.

I will analyze the words weight on Twitter for writing the website's post with Search Tweets by calculate how many tweet include the words in recently.

Will your App use Tweet, Retweet, Like, Follow, or Direct Message functionality? → Yes
Please describe your planned use of these features.

I will tweet the website's update and PV achievement automatically as my Twitter account with POST statuses/update.

Do you plan to display Tweets or aggregate data about Twitter content outside Twitter? → No

Will your product, service, or analysis make Twitter content or derived information available to a government entity? → No

規約を承認し、提出する

ページ移動し、「You now have Elevated access!」と右上にポップアップが表示される。特に審査とかは無いようだ。

Twitter APIstandard v1.1のAPIを実行しようとすると発生するエラーメッセージTwitter APIのElevated accessを申請が必要。

エラーメッセージ全文

{
  errors: [
    {
      message: '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.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve',
      code: 453
    }
  ]
}

2022年8月7日

朝からElevated accessの申請をした。

うおおおおTwitter APIでTwitterに自動投稿できるようになった!!!
やっと更新通知(と呼んでたけど記事が一定数閲覧されたらTwitter APIでTwitterに投稿)する機能を実装できるぞ!!!

記事が一定数閲覧されたらTwitter APIでTwitterに投稿する機能を実装した。

リリースした。

トークンとかの格納に.envを使っているのだけれど、これがrsyncすれば開発環境から本番環境に反映されると思っていて、本番環境でエラーを起こしていた。

2022年8月6日

Twitterへの自動投稿はめんどくさかった
ブログ更新したらTwitter APIで自動投稿したいとか考えてたけど、思ってた100倍ぐらいめんどいことが分かった

めんどくさい理由:

  • 投稿に使うtokenが有効なのは2時間だけ
  • refresh_tokenを使えばtokenの再取得ができるが、その際にrefresh_tokenも新しいものが払い出され、古いrefresh_tokenは利用できなくなる
  • 故に、DBにrefresh_tokenを入れておく必要があり、さらに常に有効であるかに気を配る必要がある
  • refresh_tokenが無効化した場合には、DBを触ってrefresh_tokenの入れ直しが必要

OAuth2.0だとめんどくさいらしく、OAuth1.0aを使った方が良いとSNSで情報をいただいた。ただ、OAuth1.0aの投稿APIはElevated accessが必要とのこと。

twitterAPIはoauth1.0aで使うのがオヌヌメ

oauth2.0はリフレッシュトークンの管理がめんどい


OAuth1.0が一生うまくいかん。
ブログ更新ツイートぐらいだったら手動でやればいいやという気持ちになってきたけど、それはそれとしてOAuth1.0に負けるわけにはいかない。

あきらめてライブラリ使ってもいいですか。

力尽きた。

丸一日OAuthに捧げたけど成果物は何もないし、いまだにAOuthって書きそうになる