无法使用PHP在博客中插入帖子

时间:2015-10-14 10:09:35

标签: php api curl oauth blogger

我使用以下代码在博客中插入帖子,但我从Google收到的回复为空。我做错了什么?

<?php
$key  = "MyKey";
$blog_id = "123456";

$url = 'https://www.googleapis.com/blogger/v3/blogs/'.$blog_id.'/posts/';
$postData = array(
    'kind' => 'blogger#post',
    'blog' => array('id' => $blog_id),
    'title' => 'This is title',
    'content' => 'This is content'
);

$data_string = json_encode($postData);

$head = array();
$head[] = 'Authorization: '.$key;
$head[] = 'Content-Type: application/json';

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$rsp = curl_exec($ch);
$results = json_decode($rsp);
var_dump($results);
?>

0 个答案:

没有答案