Fb post print
// Replace YOUR_ACCESS_TOKEN with a valid access token
const ACCESS_TOKEN = "YOUR_ACCESS_TOKEN";
async function printPostAndImageLinks(postId) {
// Fetch the post data from the Facebook Graph API
const postResponse = await fetch(
`https://graph.facebook.com/${postId}?fields=message,attachments&access_token=${ACCESS_TOKEN}`
);
const postData = await postResponse.json();
// Print the message of the post
console.log(postData.message);
// Get the attachments of the post (if any)
const attachments = postData.attachments.data;
if (attachments) {
// Print the image URLs of the attachments
attachments.forEach(attachment => {
if (attachment.type === "photo") {
console.log(attachment.media.image.src);
}
});
}
}
// Example usage:
printPostAndImageLinks("123456"); // Replace "123456" with a real Facebook post ID
Comments
Post a Comment