Closed CurssedCoffin closed 1 year ago
In the FixTweet Status Fetch API, the photos are in the tweet.media.photos?
object. If the Tweet has photos, this will be an array of the Tweet's photos, otherwise it will be undefined. The API does not explicitly have a photo count, as the length of the photos array indicates the number of photos.
In JavaScript for instance, tweet.media.photos?.length
will return the photo count or undefined if no photos. To correct for this behavior, add || 0
to ensure it always returns a number. Here's an example in JS:
const data = await fetch("https://api.fxtwitter.com/TwitterDev/status/1561833980286173186").json();
const photoCount = data.tweet.media.photos?.length || 0;
console.log(photoCount)
> 2
I hope this helps!
yes thanks!
If the tweet has multiple images, how do I know exactly the number of images to parse?