如何使用api v3在博客上发帖


How to post on blogger using api v3

这是我的代码。它对我不起作用。找不到它的输出。有人能告诉我吗?它想找什么。我在用卷发。

 $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);

这是$sd是的访问令牌

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

请告诉我我错在哪里了。

你可以使用它。希望它对你有用。

$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);
   }

根据此页面:https://developers.google.com/blogger/docs/3.0/using#AddingAPost您将需要头中的auth令牌

Authorization: /* OAuth 2.0 token here */