2013-03-26 60 views
3

我試圖通過使用api獲取博客博客信息。google api v3博客帖子插入php ajax

$blogger = new Google_BloggerService($client); 
$data = $blogger->blogs->getByUrl(array('url'=>'http://puwaruwa.blogspot.com/')); 

它工作正常,給了我細節。

然後我試圖插入後,如下

<?php 

$token = json_decode($token, true); //already got the token 

?> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<script> 
$.ajax({ 
       type:"POST", 
       url: "https://www.googleapis.com/blogger/v3/blogs/55555555555555/posts/", 
       Authorization: "OAuth <?php echo $token['access_token']; ?>", 
       data: {"kind": "blogger#post", 
       "blog": { 
       "id": "555555555555555" 
       }, 
       "title": "A new post", 
       "content": "With <b>exciting</b> content..."}, 
       dataType: 'json', 
       contentType: 'application/json', 
       success:function(data){alert(data);} 
       }); 

</script> 

,但它給了我

{ 
"error": { 
    "errors": [ 
    { 
    "domain": "global", 
    "reason": "required", 
    "message": "Login Required", 
    "locationType": "header", 
    "location": "Authorization" 
    } 
    ], 
    "code": 401, 
    "message": "Login Required" 
} 
} 

請幫我插入後使用PHP通過API V3到Blogger博客。

回答

1

這比我試圖在博客上發佈要簡單。我在這裏只介紹了這個帖子的php代碼,它對我來說工作得很好。

$blogger = new Google_BloggerService($client);  
$mypost = new Google_Post(); 
$mypost->setTitle('this is a test 1 title'); 
$mypost->setContent('this is a test 1 content'); 
$data = $blogger->posts->insert('5555555555555555555', $mypost); 

謝謝。

全面詳細的公佈是在 http://gayanonline.blogspot.com/2013/03/google-api-v3-with-php-using-blogger.html

+0

如何標記/標籤增加到帖子? – 2013-07-06 20:33:56

+0

在當前版本的google api客戶端中使用此代碼不起作用。任何消化? – BrutalApple 2015-08-13 13:28:55