sscarpa / google-api-php-client

Automatically exported from code.google.com/p/google-api-php-client
Apache License 2.0
0 stars 0 forks source link

Error calling POST: (404) Not Found' #222

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
0.6.0

Please provide any additional information below.

I am using google-api-php-client for inserting a post into my blog, but it 
returned:

<?php
  require_once 'Google_Client.php';
  require_once 'contrib/Google_BloggerService.php';

  // Set your cached access token. Remember to replace $_SESSION with a
  // real database or memcached.
  $client = new Google_Client();
  session_start();
  if (isset($_SESSION['token'])) {
    $client->setAccessToken($_SESSION['token']);
  }
  // Visit https://code.google.com/apis/console?api=plus to generate your
  // client id, client secret, and to register your redirect uri.
  $bloggerApplicationName = "xxxxxxxx";
  $bloggerEmailAddress = "xxxxxxxxxxx@developer.gserviceaccount.com";
  $bloggerClientID = "xxxxxxxxxxx.apps.googleusercontent.com";
  $bloggerKeyPath = "/home/xxxx/public_html/xxxx/xxxxxx-privatekey.p12";

  $client->setApplicationName($bloggerApplicationName);
  $client->setClientId($bloggerClientID);
  $key = file_get_contents($bloggerKeyPath);
  $client->setAssertionCredentials(new Google_AssertionCredentials($bloggerEmailAddress,array('https://www.googleapis.com/auth/blogger'),$key));

  $bloggerService = new Google_BloggerService($client);
  $bloggerPost = new Google_Post();
  $bloggerPost->setContent("test con");
  $bloggerPost->setTitle("test title");
  $bloggerPost->setLabels(array("test","title"));
  $bloggerService->posts->insert(xxxx,$bloggerPost);
  // We're not done yet. Remember to update the cached access token.
  // Remember to replace $_SESSION with a real database or memcached.
  if ($client->getAccessToken()) {
    $_SESSION['token'] = $client->getAccessToken();
  }
?>

Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error 
calling POST https://www.googleapis.com/blogger/v3/blogs/xxx/posts: (404) Not 
Found' in /home/xxx/public_html/xxx/io/Google_REST.php:64
Stack trace:
#0 /home/xxx/public_html/xxx/io/Google_REST.php(36): 
Google_REST::decodeHttpResponse(Object(Google_HttpRequest))
#1 /home/xxx/public_html/xxx/service/Google_ServiceResource.php(177): 
Google_REST::execute(Object(Google_HttpRequest))
#2 /home/xxx/public_html/xxx/contrib/Google_BloggerService.php(106): 
Google_ServiceResource->__call('insert', Array)
#3 /home/xxx/public_html/xxx/post.php(29): 
Google_PostsServiceResource->insert(xxx, Object(Google_Post))
#4 {main}
  thrown in /home/xxx/public_html/xxx/io/Google_REST.php on line 64

Please help me on how to solve the problem

Thanks,

Original issue reported on code.google.com by vcivi...@gmail.com on 19 Nov 2012 at 11:59

GoogleCodeExporter commented 8 years ago
I've found that was not caused by google api php client.

$url = "https://www.googleapis.com/blogger/v3/blogs/2090764141595158867/posts";
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
$pa = '{"content":"test con","labels":["t\u00edt","t\u1ed3"],"title":"t\u00edt 
t\u1ed3"}';
curl_setopt($ch, CURLOPT_POSTFIELDS, $pa);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("content-type: 
application/json;","content-length: ".strlen($pa),"authorization: Bearer 
ya29.xxxxxxxxx"));
echo $output = curl_exec($ch);

It returned

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}

Original comment by vcivi...@gmail.com on 20 Nov 2012 at 12:22

GoogleCodeExporter commented 8 years ago

Original comment by ianbar...@google.com on 22 Mar 2013 at 4:18