Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/249.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用PHP在blogger中插入帖子_Php_Api_Curl_Oauth_Blogger - Fatal编程技术网

无法使用PHP在blogger中插入帖子

无法使用PHP在blogger中插入帖子,php,api,curl,oauth,blogger,Php,Api,Curl,Oauth,Blogger,我正在使用以下代码在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' =

我正在使用以下代码在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);
?>


您在$rsp中得到了什么?我在$rsp中得到了布尔值false。如果您试图使用公共API密钥,那就是您的问题。您需要使用Oauth2。(客户端id和客户端机密验证用户)put
var_dump(curl_error($ch))
curl\u exec
之后,返回什么?SSL证书问题:无法获取本地颁发者证书