Search Twitter v2 Quote Retweet

Asked 1 years ago, Updated 1 years ago, 403 views

Purpose:
I'd like to get all the quotes/retweets on my tweets and the identity of the tweets from which they were quoted after the specified date and time within one week on Twitter V2.
Do not specify which tweets are quoted from.

I use Google Apps Script.
I am using the search API of Twitter v2.
The URL of the endpoint is set as follows:

const username="xxxxxx";
constendpoint="https://api.twitter.com/2/tweets/search/recent?query="+encodeURIC component('url:"https://twitter.com/"'+username+"/is:quote");

Output

{data: 
   [ 
     (Omitted)
     { edit_history_tweet_ids —Object ,
       id: '(Tweet ID of quoted retweet),
       text:'(body of quote retweet)'}',
  meta: 
   { newest_id: 'xxxx',
     oldest_id: 'xxxx',
     result_count —10,
     next_token: 'xxxxxx'}

I want to do the following.
·I want to get the ID of the original tweet as well as the quote retweet itself
·I want to get everything as well as 10 items
·I want to get a quote retweet after the specified date and time

How should I set the parameters?
I can't find out even if I look into it, so I appreciate your cooperation.

google-apps-script twitter

2023-01-28 21:32

1 Answers

To get the ID of a tweet quoted in a tweet, you can specify expansion in the query parameter - https://developer.twitter.com/en/docs/twitter-api/expansions

Specifically, you can specify expands=referenced_tweets.idHere are some examples of requests and responses:

%curl-s'https://api.twitter.com/2/tweets/search/recent?query=url%3A%22https%3A%2F%2Ftwitter.com%2Fnekketsuuu%2F%22+is%3Aquote+-is%3Aretweet&expansions=referenced_tweets.id'-H'Authorization: Bearer omitted'|jq
{
  "data": [
    {
      "id": "1619368289658093570",
      "text": "Test 2 https://t.co/eO9lOSxD53",
      rereferenced_tweets ::[
        {
          "type": "quoted",
          "id": "1619368244422533122"
        }
      ],
      "edit_history_tweet_ids":[
        "1619368289658093570"
      ]
    }
  ],
  "includes": {
    "tweets": [
      {
        "id": "1619368244422533122",
        "text": "Test",
        "edit_history_tweet_ids":[
          "1619368244422533122"
        ]
      }
    ]
  },
  "meta": {
    "newest_id": "1619368289658093570",
    "oldest_id": "1619368289658093570",
    "result_count"—1
  }
}

To get all of them, do the pageation process on the client side: https://developer.twitter.com/en/docs/twitter-api/pagination

You can use until: to retrieve tweets that are older than a certain date: https://developer.twitter.com/en/docs/twitter-api/v1/tweets/search/guides/standard-operators


2023-01-29 00:00

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.