LoginSignup
0
0

More than 1 year has passed since last update.

twitter API(投稿)使って困ったところ

Posted at

自分のサービスの告知などでTwitterに自動でツイートするシステムを作ろうと思っていろいろ試して、詰まった点などを書こうと思います。

・前提

以下二つの記事を見れば一通りできると思うので読んでみてください。

https://codechacha.com/ja/nodejs-twitter-api/
https://qiita.com/kzthrk/items/84acb969dc0b23aeae58

・自分が詰まったところ1

実行するとエラーがかえってきてエラーのメッセージを確認してみました。
you’ll need to apply for Elevated access.
ただ単に登録だけだとレベルのようなものがEssentialだからだめと言われ、Elevatedにランクアップみたいなのをしないといけませんでした。
これのためには、簡単なアンケートようなものに答えるだけです。
(どのような使い方するのか、データをアナライズする予定はあるか、など5分もあれば終わります。

image.png

エラーメッセージ本文

[ { 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 } ]

・自分が詰まったところ2

Linkを載せたかったので、"attachment_url"のパラメータで投稿しようとするとこれもエラーが返ってきました。
そこでリファレンス記載の概要を確認しました。
要はふつうのURLリンクを記載する場合にはattachment_urlは使わないでstatusの中に含んでね、ということでした。

コード的には以下の形で無事tweet出来ました。タグ追加も無事にできました。

tweet = message + " " + attachUrl + " " + tagList.join(" ")

client.post('statuses/update', { status: tweet }, function (error, tweet, response) {
    if (error) {
        console.log(error);
        throw error
    };

    console.log(tweet);  // Tweet body.
    console.log(response);  // Raw response object.
});

image.png

本文

In order for a URL to not be counted in the status body of an extended Tweet, provide a URL as a Tweet attachment. This URL must be a Tweet permalink, or Direct Message deep link. Arbitrary, non-Twitter URLs must remain in the status text. URLs passed to the attachment_url parameter not matching either a Tweet permalink or Direct Message deep link will fail at Tweet creation and cause an exception.

Google翻訳

URL が拡張ツイートのステータス本文にカウントされないようにするには、URL をツイートの添付ファイルとして提供します。この URL は、ツイートのパーマリンクまたはダイレクト メッセージのディープ リンクである必要があります。 Twitter 以外の任意の URL は、ステータス テキストに残す必要があります。ツイートのパーマリンクまたはダイレクト メッセージのディープ リンクのいずれとも一致しない attachment_url パラメーターに渡された URL は、ツイートの作成に失敗し、例外が発生します。

リファレンス(https://developer.twitter.com/en/docs/twitter-api/v1/tweets/post-and-engage/api-reference/post-statuses-update)

・最後に

google翻訳ってほんとに便利。

0
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
0
0