네이버 api 카페 글쓰기 에서 한글이 깨져서 올라갑니다. 해결 방법좀 알려주세요.

네이버 api 카페 글쓰기 에서 한글이 깨져서 올라갑니다. 해결 방법좀 알려주세요.

QA

네이버 api 카페 글쓰기 에서 한글이 깨져서 올라갑니다. 해결 방법좀 알려주세요.

답변 3

본문

네이버 api 카페 글쓰기 에서 한글이 깨져서 올라갑니다. 해결 방법좀 알려주세요.

 

로근인 후 카페에 직접 쓰는 페이지 소스 올려봅니다.

 

<?php
include('./_common.php');
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<?php

$client_id = G5_NAVER_OAUTH_CLIENT_ID; // 오픈 API 키 발급받은 client ID
$client_secret = G5_NAVER_OAUTH_SECRET_KEY; // 오픈 API 키 발급받은 client secrete
$authorize_url = 'https://nid.naver.com/oauth2.0/authorize';
$access_token_url = 'https://nid.naver.com/oauth2.0/token';

// 오픈 API 키 등록 시 입력한 callback 주소, tutorial에서는 "도메인주소/callback.php".
$callback_uri = 'http://www.formebnm.co.kr/plugin/naver/callback.php?service=naverc';
$index_uri = 'http://www.formebnm.co.kr/plugin/naver/blog_write.php'; // tutorial에서는 "도메인주소/index.php"

$cafe_id = "xxxxxxxxxx";
$board_id = "x";

function generate_state(){
 $mt = microtime();
 $rand = mt_rand();
 return md5($mt . $rand);
}

$bo_table = get_session('nb_bo_table');
$wr_id = get_session('nb_wr_id');

if($_SESSION['access_token']) {
 header("Content-Type: text/html; charset=UTF-8");
 $bo_table = get_session('nb_bo_table');
 $wr_id = get_session('nb_wr_id');
 
 $sql = "select * from ".$g5['write_prefix'].$bo_table." where wr_id = ".$wr_id."";
 $row = sql_fetch($sql);

 $subject = $row['wr_subject'];
 $content = $row['wr_content'];
 
 $token = $_SESSION['access_token']; // 네이버 로그인 API호출로 받은 접근 토큰값
 
 $header = "Bearer ".$token; // Bearer 다음에 공백 추가
 $clubid = $cafe_id;// 카페의 고유 ID값
 $menuid = $board_id; // 카페 게시판 id
 
 $url = "https://openapi.naver.com/v1/cafe/".$clubid."/menu/".$menuid."/articles";
 
  
 $postvars = array(
  'subject' => urlencode($subject),
  'content' => urlencode($content)
 );

 $postvars_string = "";

 foreach($postvars as $key => $value) {
  $postvars_string .= $key. "=". $value. "&";
 }
 $postvars_string = rtrim($postvars_string, '&');

 $is_post = true;
 
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_POST, count($postvars));
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch,CURLOPT_POSTFIELDS, $postvars_string);
 $headers[] = "Authorization: ".$header;
 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 $response = curl_exec ($ch);
 $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
 curl_close ($ch);
 
 if($status_code == 200) {
  alert_close('정상적으로 게시 되었습니다.');
 } else {
  echo "Error 내용:".$response;
  exit;
 }
}
?>
</body>
</html>

 

 

이 질문에 댓글 쓰기 :

답변 3


 $postvars = array(
  'subject' => urlencode(urlencode($subject)),
  'content' => urlencode(urlencode($content))
 ); 

로 하시면됩니다.

 

저도 해결하고 나서 어이가 없네요 ㅎㅎㅎ.......

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 12
© SIRSOFT
현재 페이지 제일 처음으로