尝试使用API​​向博客添加帖子时出现无效的凭据错误

时间:2015-10-15 07:48:33

标签: php api curl oauth-2.0 blogger

我试图从昨天开始使用API​​向博客添加帖子,但没有运气。这是我的代码。当我运行它时,我得到了#34; Invalid Credentials"错误。

我还在下面发布了截图,其中显示了我在Google Developer Console中获取该密钥的位置。可能是我拿错了钥匙?

代码

<?php
$key  = "J7c";
$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);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$rsp = curl_exec($ch);
$results = json_decode($rsp);
var_dump($rsp);
?>

错误
enter image description here

Google Developer Console
enter image description here

0 个答案:

没有答案