지금 쓰는 시간 아깝다! 블로그 글 자동 작성·발행 완벽 가이드

후킹제목으로 본문은 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);

  }

}


function publishPostToWordPress(title, content) {
  const wpUrl = PropertiesService.getScriptProperties().getProperty('WORDPRESS_URL'); // 예: https://yourdomain.com
  const wpUsername = PropertiesService.getScriptProperties().getProperty('WORDPRESS_USERNAME'); // 예: admin
  const wpAppPassword = PropertiesService.getScriptProperties().getProperty('WORDPRESS_APPLICATION_PASSWORD'); // 공백 포함

  if (!wpUrl || !wpUsername || !wpAppPassword) {
    throw new Error("⚠️ WordPress 설정이 누락되었습니다. setWordPressCredentials() 함수를 먼저 실행하세요.");
  }

  const apiUrl = wpUrl.replace(/\\/$/, "") + "/wp-json/wp/v2/posts"; // 마지막 / 제거 후 REST 경로 추가
  const credentials = Utilities.base64Encode(`${wpUsername}:${wpAppPassword}`);
  
  const headers = {
    "Authorization": `Basic ${credentials}`,
    "Content-Type": "application/json"
  };

  const payload = {
    title: title,
    content: content,
    status: "publish" // draft, publish, pending 선택 가능
    // 카테고리 ID나 태그 ID는 필요시 추가
  };

  const options = {
    method: "post",
    headers: headers,
    payload: JSON.stringify(payload),
    muteHttpExceptions: true
  };

  const response = UrlFetchApp.fetch(apiUrl, options);
  const result = JSON.parse(response.getContentText());

  if (response.getResponseCode() !== 201) {
    Logger.log("🚨 발행 실패: " + JSON.stringify(result));
    throw new Error(`워드프레스 발행 오류: ${response.getResponseCode()}`);
  }

  Logger.log("✅ 워드프레스 발행 성공: " + result.link);
  return result.link;
}

이 블로그의 인기 게시물

윈도우 시작 버튼 작업표시줄 클릭 안됨 먹통 해결 복구 고장

오토캐드 단축키 설정 다른 컴퓨터로 옮기는 3가지 방법 (2025 최신)

C언어로 실수 입력받고 소수점·지수 출력하는 초간단 방법초 마스터 %f %e printf