function createThreadAuthenticatedWithDynamicNews() {
// --- Configuration ---
const threadUrl = 'https://bharatchan.com/post/create/thread';
const imageUrl = 'https://pic.re/image';
// Your specific session cookie value
const sessionCookieValue = 's%3AVe305li6DdNUE0UjPtw1y4VxBNLr_qI4.9BSRpx6R%2F64GpyMAnhncFb2cfrNeVprhazPTDK6Di60';
// --- 1. Generate Latest News Content ---
// This content is dynamically generated based on the search results at runtime.
const latestNews = `
🚨 **BREAKING NEWS - ${new Date().toLocaleDateString()}** 🚨
* **World:** Hong Kong high-rise fire death toll rises, with hundreds still missing.
* **US:** White House shooting incident leaves National Guard members injured; suspect in custody.
* **India:** GRAP-3 restrictions in Delhi revoked as air quality shows slight improvement.
* **Markets:** Indian stock market's Nifty and Sensex hit new all-time highs.
* **Sports:** South Africa clinches a historic series win against India, dealing them a rare home loss.
---
This post was generated and authenticated via Google Apps Script.
[Image attached via 'media' field]
`;
// --- 2. Fetch the Image as a Blob ---
let imageBlob;
try {
const imageResponse = UrlFetchApp.fetch(imageUrl);
imageBlob = imageResponse.getBlob();
imageBlob.setName("latest_news_image.jpg");
Logger.log(`Successfully fetched image with type: ${imageBlob.getContentType()}`);
} catch (e) {
Logger.log(`🚨 ERROR: Failed to fetch image from URL: ${e.toString()}`);
return; // Stop execution if image fetch fails
}
// --- 3. Define the Payload (Text and File) ---
const payloadObject = {
// The 'form-content' field now contains the dynamically fetched news
'form-content': latestNews,
// The 'media' field uses the fetche