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
- Log the Exact Error Details: In the Apps Script publishPost function, catch and log the full response:
javascript
try {
const response = UrlFetchApp.fetch(url, options);
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.
- 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.
- 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(selectedP
let html = `<h3>${CAPTION}</h3><div style="display: flex; justify-content: space-around; flex-wrap: wrap;">`;
selectedProfiles.forEach(profi
// Assume profile = [name, linkedin, photo, email]; escape for safety
const name = Utilities.jsonStringify(profil
const linkedin = profile[1];
let photo = profile[2] || 'https://via.placeholder.com/
const email = Utilities.jsonStringify(profil
// Basic URL validation (optional: fetch head to check 200, but adds time)
if (!photo.startsWith('http')) photo = 'https://via.placeholder.com/
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://
<p><a href="${linkedin}" target="_blank">${name}</a></
<p>Email: <a href="mailto:${email}">${email
</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