0. 게시판 관리자에서
test
게시판을 만들어 준다.
1. 테마의 tail.php 나 index.php 혹은 적당한 곳에 아래 스크립트 넣기
- 자동으로 밴드글을 가져오는 역할을 함.
<script>
$.ajax({
url: '/api/band_posts.php', // 요청 할 주소
async: false, // false 일 경우 동기 요청으로 변경
type: 'POST', // GET, PUT
data: {
}, // 전송할 데이터
dataType: 'text', // xml, json, script, html
success: function(jqXHR) {console.log('success');}, // 요청 완료 시
error: function(jqXHR) {console.log('error');}, // 요청 실패.
});
</script>
2. 해당 경로에 아래 파일 만들어 넣기
/* /api/band_posts.php */
<meta charset="utf-8">
<?
include_once('./_common.php');
/*
https://developers.band.us
네이버 밴드 개발자 사이트에서 내 서비스등록후, Aaccess Token 을 발급받는다.
밴드 목록에서 밴드키 찾기 부분, 밴드키를 찾은 후에는 해당 부분만 주석처리 한다.
*/
/************************************************************************************
$url = 'https://openapi.band.us/v2.1/bands';
$ch = curl_init();
$data = "access_token=네이버 밴드에서 발급받은 토큰키를 넣는다.";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, 0); // 헤더 출력 여부
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 결과값을 받을것인지
$result=curl_exec($ch);
curl_close ($ch);
var_dump($result);
**************************************************************************************/
//밴드 게시글 가져오기
$url = 'https://openapi.band.us/v2/band/posts';
$ch = curl_init();
$data = "access_token=네이버 밴드에서 발급받은 토큰키를 넣는다.&band_key=위밴드키 찾기부분에서 얻은 밴드키를 넣는다.";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, 0); // 헤더 출력 여부
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 결과값을 받을것인지
$result=curl_exec($ch);
curl_close ($ch);
$jsonData = json_decode($result, true);
$bo_table = "test";
// 게시판 ID를 넣는다.
$write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
foreach ($jsonData['result_data']['items'] as $items) {
//포스트글 중복체크
$cnt = sql_fetch("select wr_id from $write_table where wr_1 = '".trim($items['post_key'])."' ");
if( $cnt>0 || $items['content']=='Uploaded event.' ) {
continue;
} else {
$wr_date_time = date('Y-m-d H:i:s',substr($items['created_at'],0,10));
$wr_subject = "네이버 밴드글 (".substr($wr_date_time,0,10).")";
// 제목은 적당하게 넣어 준다.
$wr_content = substr(trim(nl2br($items['content'])),0,65536);
$wr_content = preg_replace("#[\\\]+$#", "", $wr_content);
$mb_id = "admin";
$wr_name = "운영자";
// 게시자 이름도 적당하게 넣어 준다.
$wr_password = get_encrypt_string("1a2a3a4a5a6a");
$wr_email = '';
$wr_num = get_next_num($write_table);
$wr_reply = '';
$html = "html2";
// 포스트 키
$wr_1 = trim($items['post_key']);
$tmp_photo = "";
foreach($items['photos'] as $photo){
$tmp_photo .= '<img src="'.$photo['url'].'" alt="band images" ><br><br>';
}
$wr_content .= $tmp_photo;
$sql = " insert into $write_table
set wr_num = '$wr_num',
wr_reply = '$wr_reply',
wr_comment = 0,
ca_name = '',
wr_option = '$html,$secret,$mail',
wr_subject = '$wr_subject',
wr_content = '$wr_content',
wr_link1 = '',
wr_link2 = '',
wr_link1_hit = 0,
wr_link2_hit = 0,
wr_hit = 0,
wr_good = 0,
wr_nogood = 0,
mb_id = '{$mb_id}',
wr_password = '$wr_password',
wr_name = '$wr_name',
wr_email = '$wr_email',
wr_homepage = '',
wr_datetime = '".$wr_date_time."',
wr_last = '".$wr_date_time."',
wr_ip = '{$_SERVER['REMOTE_ADDR']}',
wr_1 = '$wr_1',
wr_2 = '',
wr_3 = '',
wr_4 = '',
wr_5 = '',
wr_6 = '',
wr_7 = '',
wr_8 = '',
wr_9 = '',
wr_10 = '' ";
sql_query($sql);
$wr_id = sql_insert_id();
// 부모 아이디에 UPDATE
sql_query(" update $write_table set wr_parent = '$wr_id' where wr_id = '$wr_id' ");
// 새글 INSERT
sql_query(" insert into {$g5['board_new_table']} ( bo_table, wr_id, wr_parent, bn_datetime, mb_id ) values ( '{$bo_table}', '{$wr_id}', '{$wr_id}', '".G5_TIME_YMDHIS."', '{$member['mb_id']}' ) ");
// 게시글 1 증가
sql_query("update {$g5['board_table']} set bo_count_write = (select count(wr_id) from $write_table where 1=1) where bo_table = '{$bo_table}'");
}
}
?>
3. 밴드 게시물은 등록된 역순으로 가져오게 되므로,
게시판 관리자에서 정렬순서를 wr_datetime desc 로 변경해 준다.
4. 다음 작업할때 쓸려고 팁자료실에 남겨 본다. 끝.
5. 추가
=================
해당 경로에 파일 만들기
/* /api/_common.php */
<?php
include_once('../common.php');
?>
/*
이 파일이 없으면 오류가 나고 DB 연결이 안됨.
그누보드 기본내용이라서 생략하였으나, 추가함.
*/
댓글 33개
https://openapi.band.us/ 이걸로 토큰 값과 밴드 키 값 입력해서 밴드 정보를 불러오는 것까지는 잘 되는데, 그누보드에서 불러오지 못하고 있습니다. 경로 값이 잘못된 건지 URI 값이 잘못된 건지 이것저것 적용시켜 보는데도 잘 안 되네요.
현재 두개의 그누보드를 따로 적용해서 운영하고 있어서
처음 인덱스에
<?php
$url="g5";
header ("Location: $url");
?>
이걸 적용시켜서 도메인주소를 입력하면 바로 g5로 가도록 했는데요.
(예를 들어 asdf.com 주소를 치면 asdf.com/g5 로 이동하게 했습니다.)
이렇게 되면
url: '/api/band_posts.php', // 요청 할 주소 이게 바뀌어야 하는 건가요? api 경로에 다 적용시켜봐도 잘 안 되네요.
아니면 Redirect URI 경로에 문제가 있는 것인지 잘 모르겠네요.
예를 들어 http://www.asdf.com/g5/api/ 하면 될까요?
제대로 배운 적이 없어서 참 어렵네요 ㅠㅠ
알려주신 대로 적용을 시켰는데요. 그래도 게시판에 불러오지는 못하네요.
혹시 아래에서 제가 필수로 넣어야 하는 정보가 있나요?
아니면, 지금 그누보드의 게시글에 등급 설정을 하여 등급에 맞는 사람만 글을 쓰거나 보게 하고 있는데, 등급 설정을 다 풀고 적용을 시켜야 하는 건지요?
$write_table = $g5['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
foreach ($jsonData['result_data']['items'] as $items) {
//포스트글 중복체크
$cnt = sql_fetch("select wr_id from $write_table where wr_1 = '".trim($items['post_key'])."' ");
if( $cnt>0 || $items['content']=='Uploaded event.' ) {
continue;
} else {
$wr_date_time = date('Y-m-d H:i:s',substr($items['created_at'],0,10));
$wr_subject = "네이버 밴드글 (".substr($wr_date_time,0,10).")";
// 제목은 적당하게 넣어 준다.
$wr_content = substr(trim(nl2br($items['content'])),0,65536);
$wr_content = preg_replace("#[\\\]+$#", "", $wr_content);
$mb_id = "admin";
$wr_name = "운영자";
// 게시자 이름도 적당하게 넣어 준다.
$wr_password = get_encrypt_string("1a2a3a4a5a6a");
$wr_email = '';
좋은 자료를 주셨는데, 제가 제대로 활용을 못하네요 ㅠㅠ
게시글 목록
| 번호 | 제목 |
|---|---|
| 24149 | |
| 24140 | |
| 24133 | |
| 24125 | |
| 24119 | |
| 24109 | |
| 24105 | |
| 24101 | |
| 24093 | |
| 24089 | |
| 24077 | |
| 24074 | |
| 24071 | |
| 24070 | |
| 24067 | |
| 24056 | |
| 24050 | |
| 24046 | |
| 24043 | |
| 24040 | |
| 24037 | |
| 24036 | |
| 24035 | |
| 24034 | |
| 24021 | |
| 24017 | |
| 24005 | |
| 24002 | |
| 23990 | |
| 23980 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기