i want to add new post in blogger using google API v3. I was created API Key in console.google.com and using this code:
$url = 'https://www.googleapis.com/blogger/v3/blogs/'.$blogid.'/posts/';
$postData = array(
'kind' => 'blogger#post',
'blog' => array('id' => $blogid),
'title' => 'This is title',
'content' => 'With <b>exciting</b> content...'
);
$head = array();
$head[] = 'Authorization: '.$token;
$head[] = 'Content-Type: application/json';
$page = curl($url, json_encode($postData), '', $head);
var_dump($page);
$token is a API key, but respose error.
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
Everybody, can you help me. Thanks so much !
Token shouldn't be an API key but the access token.
You can generate your access token here - https://developers.google.com/oauthplayground/
Better make a request using Step 3 at the playground itself to check the request headers and body and make sure that your sending the Post request in the same manner.
( Make sure to add Bearer before the Token as you would see in the request made through Oauth 2 Playground)