3

我试图通过使用 api 来获取博主的博客信息。

    $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"
 }
}

请帮助我通过 api v3 使用 php 将帖子插入博客博客。

4

1 回答 1

0

这比我试图在博客上发帖要简单。我在这里只展示发布帖子的 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

于 2013-03-27T03:32:34.230 回答