Closed5

Twitter APIで403エラーが急に発生した時の対応メモ

t0m0120t0m0120

TL;DR

  • 急に403エラー
  • X Developer Portalで エラーの出てるAppをProjectのAppsへ紐づける

運用しているTwitterのBotで下記のエラーが急に発生。
ツイートが全くできなくなったので、対応する。

エラーが発生しました。
Twitter.post
Twitter API エラー: 403
{"client_id":"1234","detail":"When authenticating requests to the Twitter API v2 endpoints, you must use keys and tokens from a Twitter developer App that is attached to a Project. You can create a project via the developer portal.","registration_url":"https://developer.twitter.com/en/docs/projects/overview","title":"Client Forbidden","required_enrollment":"Appropriate Level of API Access","reason":"client-not-enrolled","type":"https://api.twitter.com/2/problems/client-forbidden"%7D

t0m0120t0m0120

メッセージを翻訳すると下記。

「Twitter API v2エンドポイントへのリクエストを認証する際は、プロジェクトにアタッチされているTwitter開発者アプリのキーとトークンを使用する必要があります。
プロジェクトは開発者ポータルから作成できます。」

元々投稿できており、キーやトークンに問題はないはず。
プロジェクトにアタッチされなくなった?


とりあえずX Developer Portalにアクセスしてみる。
該当するTwitterのプロジェクトがSTANDALONE APPSのBot1に該当することになっていた。
(実装したのが数年以上前なので覚えてないが、こんな項目あったっけ?)

t0m0120t0m0120

ProjectにAppをリンクする

Projectページの下部のAppsに「Add App」ボタンがあるので、ここからリンクする。

Add an exisiting を選択。

該当するアプリを選択。

これでアプリにプロジェクトを追加できたはず。

このスクラップは4ヶ月前にクローズされました