작성한 글을 구글 blogger에 글 보내기(등록하기) 질문 드립니다,

작성한 글을 구글 blogger에 글 보내기(등록하기) 질문 드립니다,

QA

작성한 글을 구글 blogger에 글 보내기(등록하기) 질문 드립니다,

본문

그누보드에서 작성한 글을 구글 블로거(blogger)로 SNS공유하기 처럼 보내기 하려고 합니다.

Blogger API v3를 이용하여 작업을 하려고 하는데 쉽지가 않네요.

 

API Key 만들어 

https://developers.google.com/apis-explorer 에서 온라인으로 테스트를 하면 글 등록이 잘 되는데

php로 만든 소스를 이용하면 전혀 글 등록이 되지 않는군요.

 

사용한 예제 소스는 

http://gayanonline.blogspot.kr/2013/03/google-api-v3-with-php-using-blogger.html

 


<?php
session_start();
require_once dirname(__FILE__).'/GoogleClientApi/src/Google_Client.php';
require_once dirname(__FILE__).'/GoogleClientApi/src/contrib/Google_BloggerService.php';
$scriptUri = "http://".$_SERVER["HTTP_HOST"].$_SERVER['PHP_SELF'];
$client = new Google_Client();
$client->setAccessType('online'); // default: offline
$client->setApplicationName('giaws'); //name of the application
$client->setClientId('345345345645.apps.googleusercontent.com'); //insert your client id
$client->setClientSecret('JHJUGHJH6556vhjVHJKds'); //insert your client secret
$client->setRedirectUri($scriptUri); //redirects to same url
$client->setDeveloperKey('jhvjhhj6fvdfvfdv763248732QHGHJBHJ'); // API key (at bottom of page)
$client->setScopes(array('https://www.googleapis.com/auth/blogger')); //since we are going to use blogger services
$blogger = new Google_BloggerService($client);
if (isset($_GET['logout'])) { // logout: destroy token
    unset($_SESSION['token']);
 die('Logged out.');
}
if (isset($_GET['code'])) { // we received the positive auth callback, get the token and store it in session
    $client->authenticate();
    $_SESSION['token'] = $client->getAccessToken();
}
if (isset($_SESSION['token'])) { // extract token from session and configure client
    $token = $_SESSION['token'];
    $client->setAccessToken($token);
}
if (!$client->getAccessToken()) { // auth call to google
    $authUrl = $client->createAuthUrl();
    header("Location: ".$authUrl);
    die;
}
//you can get the data about the blog by getByUrl
$data = $blogger->blogs->getByUrl(array('url'=>'http://puwaruwa.blogspot.com/'));
//creates a post object
$mypost = new Google_Post();
$mypost->setTitle('this is a test 1 title');
$mypost->setContent('this is a test 1 content');
$data = $blogger->posts->insert('546547654776577', $mypost); //post id needs here - put your blogger blog id
 var_dump($data);
?>

 

 

Blogger API v3 document에는

https://developers.google.com/blogger/docs/3.0/using

 

Adding a post

https://www.googleapis.com/blogger/v3/blogs/blogId/posts/

 

Request


POST https://www.googleapis.com/blogger/v3/blogs/8070105920543249955/posts/
Authorization: /* OAuth 2.0 token here */
Content-Type: application/json
{
  "kind": "blogger#post",
  "blog": {
    "id": "8070105920543249955"
  },
  "title": "A new post",
  "content": "With <b>exciting</b> content..."
}

 

Response


{
 "kind": "blogger#post",
 "id": "6819100329896798058",
 "blog": {
  "id": "8070105920543249955"
 },
 "published": "2012-05-20T20:08:00-07:00",
 "updated": "2012-05-20T20:08:35-07:00",
 "url": "http://brettmorgan-test2.blogspot.com/2012/05/new-post.html",
 "selfLink": "https://www.googleapis.com/blogger/v3/blogs/8070105920543249955/posts/6819100329896798058",
 "title": "A new post",
 "content": "With <b>exciting</b> content...",
 "author": {
  "id": "16258312240222542576",
  "displayName": "Brett Morgan",
  "url": "http://www.blogger.com/profile/16258312240222542576",
  "image": {
   "url": "https://resources.blogblog.com/img/b16-rounded.gif"
  }
 },
 "replies": {
  "totalItems": "0",
  "selfLink": "https://www.googleapis.com/blogger/v3/blogs/8070105920543249955/posts/6819100329896798058/comments"
 }
}

 

Blogger API를 이용하여 글 등록 성공 하신 분이나 참고가 될 수 있는 예제 있으시면

이에 대한 조언 부탁 드립니다.

 

감사합니다.

이 질문에 댓글 쓰기 :

답변을 작성하시기 전에 로그인 해주세요.
전체 123,629 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT