Twitter V2 Get Tweets API's Query Parameter not working

43 views Asked by At

I'm following this twitter api documentation to get detailed information for a tweet, but I can't seem to get the full tweet details (retweet count, hearts, geotags etc etc) with this API. I'm only getting this response for from the API for a tweet:

{
  edit_history_tweet_ids: [ '1766576440005333244' ],
  id: '1766576440005333244',
  text: 'RT @MOdesign19: Congratulations KTR. #saloneX #supportlocalfootball'
}

I've put the proper query parameters (like expansions, tweet.fields), but nothing seems to be getting me a detailed report of the tweet. This is what my code looks like:

const needle = require("needle");

const YOUR_BEARER_TOKEN = "MY-TOKEN-HERE";
const TWEET_ID = "1766576440005333244"; // Replace with the actual tweet ID

// Define the endpoint URL
const endpointUrl = `https://api.twitter.com/2/tweets/${TWEET_ID}`;

// Set up the request headers
const headers = {
  Authorization: `Bearer ${YOUR_BEARER_TOKEN}`,
  "Content-Type": "application/json",
};
// Specify the fields you want to retrieve
const tweetFields =
  "attachments,author_id,context_annotations,conversation_id,created_at,entities,geo,id,in_reply_to_user_id,lang,non_public_metrics,public_metrics,organic_metrics,promoted_metrics,possibly_sensitive,referenced_tweets,reply_settings,source,text,withheld";

// Set up the request parameters including the desired fields
const params = {
  "tweet.fields":
    "attachments,author_id,context_annotations,conversation_id,created_at,entities,geo,id,in_reply_to_user_id,lang,public_metrics,referenced_tweets,reply_settings,source,text,withheld",
  expansions: "author_id",
  "user.fields":
    "created_at,description,entities,id,location,name,pinned_tweet_id,profile_image_url,protected,public_metrics,url,username,verified,verified_type,withheld",
  "media.fields":
    "duration_ms,height,media_key,preview_image_url,type,url,width,public_metrics,alt_text,variants",
  "place.fields":
    "contained_within,country,country_code,full_name,geo,id,name,place_type",
  "poll.fields": "duration_minutes,end_datetime,id,options,voting_status",
};

async function helloWorld() {
  // Make the GET request
  const response = await needle("get", endpointUrl, params, { headers });
  console.log(response.body.data);
}

helloWorld();
0

There are 0 answers