Hi Friends,

Even as I launch this today ( my 80th Birthday ), I realize that there is yet so much to say and do. There is just no time to look back, no time to wonder,"Will anyone read these pages?"

With regards,
Hemen Parekh
27 June 2013

Now as I approach my 90th birthday ( 27 June 2023 ) , I invite you to visit my Digital Avatar ( www.hemenparekh.ai ) – and continue chatting with me , even when I am no more here physically

Tuesday, 28 October 2025

Take a look

 Hey Grok Bhai : Kishan implemented this today but we are facing problems. Some blogs are NOT getting auto-uploaded on Blogger ( www.HemenParekh.in ) although these are getting uploaded on Linkedin . Here is a message from Kishan . Any idea what could be the problem and how to resolve it ? Messages > Kishan

Dear Hemen Bhai,

Thanks for looping me in—sorry to hear about the upload hiccups with Blog Genie. Kishan's hunch is spot on: A 400 error from the Blogger API on posts.insert is almost always a "Bad Request" tied to the payload (like invalid JSON structure or malformed HTML in the content field), not auth or quotas. Since it started this morning and only hits some posts (e.g., the MUDRA Yojana one), it's likely the new executive profiles HTML triggering a parse issue—maybe unescaped quotes, invalid image URLs, or even Blogger's sanitizer choking on certain tags/styles. LinkedIn's API is more forgiving with HTML, which explains why those uploads succeed.

Quick Diagnosis Steps for Kishan

  1. Log the Exact Error Details: In the Apps Script publishPost function, catch and log the full response:

javascript

try {

  const response = UrlFetchApp.fetch(urloptions);

  if (response.getResponseCode() !== 200) {

    const errorText = response.getContentText();

    console.error('Blogger API Error:'errorText);  // This will show in Executions log

    throw new Error(`HTTP ${response.getResponseCode()}: ${errorText}`);

  }

  // ... rest of success handling

catch (e) {

  console.error('Publish failed:'e.toString());

}

Run a failing post and check the Apps Script Executions log (script.google.com > Executions). Look for specifics like "invalidContent", "parseError", or details on the bad HTML element. Compare a working post's payload vs. a failing one.

  1. Test Payload Validation:
    • Manually test the API via Google's API Explorer (developers.google.com/blogger/api/reference/rest/v3/posts/insert). Paste the exact postContent + profilesHTML from a failing post. If it 400s there, the issue is confirmed as content-related.
    • Check for common HTML gotchas in generateProfilesHTML:
      • Unescaped " in names/emails (e.g., if a name has "O'Reilly", it breaks JSON). Fix: Use Utilities.jsonStringify() on user inputs.
      • Invalid/broken photo URLs (Blogger rejects non-200 images). Add a try-catch or pre-validate.
      • Overly long/complex HTML (Blogger has ~1MB limits; trim if needed).
      • Sanitize: Blogger strips <script>, but rogue tags like unclosed <div> can parse-fail.
  2. Rate Limits? Unlikely Here: No daily upload cap mentioned in docs (just 100 reqs/100s per user, but 2/5 posts succeeding rules this out). If it were quotas, it'd be 403 "Rate Limit Exceeded," not 400.

Resolution Plan

Once you have the error log, it'll pinpoint it—probably a quick HTML tweak. In the meantime, here's an updated generateProfilesHTML function with safer escaping and validation (replace in Code.gs). It JSON-escapes fields, adds alt fallbacks, and limits to valid HTML:

javascript

function generateProfilesHTML(selectedProfiles) {

  let html = `<h3>${CAPTION}</h3><div style="display: flex; justify-content: space-around; flex-wrap: wrap;">`;

  selectedProfiles.forEach(profile => {

    // Assume profile = [name, linkedin, photo, email]; escape for safety

    const name = Utilities.jsonStringify(profile[0]).slice(1-1);  // Strip quotes

    const linkedin = profile[1];

    let photo = profile[2|| 'https://via.placeholder.com/100?text=No+Photo';  // Fallback

    const email = Utilities.jsonStringify(profile[3]).slice(1-1);

   

    // Basic URL validation (optional: fetch head to check 200, but adds time)

    if (!photo.startsWith('http')) photo = 'https://via.placeholder.com/100?text=Invalid';

   

    html += `

      <div style="text-align: center; margin: 10px; width: 150px;">

        <img src="${photo}" alt="${name}" style="width: 100px; height: 100px; border-radius: 50%; object-fit: cover;" onerror="this.src='https://via.placeholder.com/100?text=Error';">

        <p><a href="${linkedin}" target="_blank">${name}</a></p>

        <p>Email: <a href="mailto:${email}">${email}</a></p>

      </div>`;

  });

  html += `</div>`;

  return html;

}

For the payload in publishPost, ensure it's valid JSON—double-check with JSON.stringify(payload) logging.

If the log shows something else (e.g., auth drift), re-run the OAuth flow. Test with a minimal post (no profiles) to isolate.

This should nail it in under an hour of debugging. Ping me the error log snippet if you share, and I'll refine further. Let's get those blogs flowing smoothly!

Best, Grok Bhai

 

 

With regards,

 

Hemen Parekh 

No comments:

Post a Comment