지금 쓰는 시간 아깝다! 블로그 글 자동 작성·발행 완벽 가이드
후킹제목으로 본문은 2000자로 gpt4로 seo최적화글을 작성하는 코드입니다.
function generateHookedArticleWithGPT(topic) {
const apiKey = PropertiesService.getScriptProperties().getProperty('OPENAI_API_KEY');
if (!apiKey) {
throw new Error("❌ OpenAI API 키가 설정되지 않았습니다. setOpenAiApiKey()를 먼저 실행하세요.");
}
const apiUrl = "https://api.openai.com/v1/chat/completions";
const headers = {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json"
};
const prompt = `
당신은 클릭을 유도하는 후킹 제목을 잘 짓는 SEO 콘텐츠 작가입니다.
다음 주제를 바탕으로 구글 애드센스 승인에 적합한 고품질 블로그 글을 작성하세요:
📝 주제: "${topic}"
요구 조건:
1. 후킹성 강한 제목 1개 (15자~30자 이내)
2. 본문 글자 수는 공백 제외 약 2,000자 이상
3. 소제목(H2)은 최소 3개 이상
4. SEO를 고려한 키워드 중심 구성
5. 마무리 단락(결론) 포함
6. 문장은 자연스럽고, 복사글이 아니어야 함
7. 한국어로 작성하세요
출력 형식은 아래처럼 해주세요:
제목:
[여기에 제목]
본문:
<h2>[소제목1]</h2>
내용...
<h2>[소제목2]</h2>
내용...
<h2>[소제목3]</h2>
내용...
<h2>결론</h2>
내용...
`;
워드프레스REST API를 이용해서 자동발행하는 코드
const payload = {
model: "gpt-4o",
messages: [
{ role: "system", content: "당신은 SEO 최적화 블로그 글을 쓰는 콘텐츠 마케팅 전문가입니다." },
{ role: "user", content: prompt }
],
temperature: 0.7,
max_tokens: 3000
};
const options = {
method: "post",
headers: headers,
payload: JSON.stringify(payload),
muteHttpExceptions: true
};
try {
const response = UrlFetchApp.fetch(apiUrl, options);
const json = JSON.parse(response.getContentText());
if (json.choices && json.choices.length > 0) {
return json.choices[0].message.content.trim();
} else {
throw new Error("❌ GPT 응답 오류: 결과 없음");
}
} catch (e) {
throw new Error("❌ API 호출 실패: " + e.message);
}
}
.jpg)