Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Twitter V2 Get Tweets API's Query Parameter not working #152

Open
Prottoy2938 opened this issue Mar 14, 2024 · 1 comment
Open

Twitter V2 Get Tweets API's Query Parameter not working #152

Prottoy2938 opened this issue Mar 14, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Prottoy2938
Copy link

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 a tweet from the API:

{
  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();
@Prottoy2938 Prottoy2938 added the bug Something isn't working label Mar 14, 2024
@Prottoy2938
Copy link
Author

any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant