user6239042
user6239042

Reputation:

How to post on blogger using api v3

Here is my code. Its not working for me. its output is Not found. Can anyone please tell me. What it is trying to find. I am using curl.

 $datas =array(
'kind' => 'blogger#post',
'blog' => array('id' => '3830391901953093498'),
'title' => 'This is title',
'content' => 'With <b>exciting</b> content...'
 );
 $data_json = json_encode($datas, JSON_HEX_QUOT + JSON_HEX_TAG + JSON_HEX_AMP +    JSON_HEX_APOS + JSON_FORCE_OBJECT);
 $dat = strlen($data_json);
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,'https://www.googleapis.com/blogger/v3/blogs/3830391901953093498/posts&access_token='.$sd);
curl_setopt($ch, CURLOPT_POST, $dat);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
$rep=curl_exec($ch);
curl_close($ch);

Here is $sd is access token that is

$token = $_SESSION['token'];
$kd = json_decode($token);
 $sd = $kd->access_token;

Please tell me where Am I wrong.

Upvotes: 1

Views: 4073

Answers (2)

Cwissy
Cwissy

Reputation: 2156

according to this page: https://developers.google.com/blogger/docs/3.0/using#AddingAPost you are going to need the auth token in the header

Authorization: /* OAuth 2.0 token here */

Upvotes: 0

Shawon
Shawon

Reputation: 322

Well you can use it. Hope it works for you.

$blogger = new Google_Service_Blogger($client);
try {
$blog = $blogger->blogs->getByUrl("http://hollywood159.blogspot.in");
   // creates a post
   $mypost = new Google_Service_Blogger_Post();
   $mypost->setTitle("the title");
   $mypost->setLabels("my labels array");
   $mypost->setContent("my content");
   $blogger->posts->insert($blog->getId(), $mypost);

   }

Upvotes: 4

Related Questions