List Blogger entries via API v3 with PHP Google_Client, Google_Service_Blogger

I am using the Google PHP client library to access the Google APIs (see link )

I am trying to get a list of posts from a private blog (the same content that can be found in the RSS feed). Private blogs of bloggers obviously do not have open RSS feeds, so this is my attempt for both

  • programmatically restore blog content
  • satisfy blog privacy restrictions.

The token used in the API client is an authorized blog reader.

Here is the code. Everything works fine (it connects, retrieves the correct blog object, etc.), but it fails when trying to get post data directly using the getItems function (see library source , line 2007). empty array is returned.

$client= new Google_Client();
$client->setClientId(GGL_CLIENTID);
$client->setClientSecret(GGL_SECRET);
$client->setRedirectUri(GGL_REDIRECT);
$client->refreshToken(GGL_TOKEN);
$service=new Google_Service_Blogger($client);

$blog      = $service->blogs->getByUrl('http://MYBLOG.blogspot.com/');
$blogName  = $blog->getName();
$blogUrl   = $blog->getURL();
$postsObj  = $blog->getPosts();
$postCount = $postsObj->getTotalItems();
$posts     = $postsObj->getItems();

echo "BLOG NAME: $blogName \n";
echo "BLOG URL: $blogUrl \n";
echo "TOTAL POSTS: $postCount \n";
echo "POST DATA: \n"; print_r($posts);

Given that the correct number of messages appears through getTotalItems, I am convinced that all the plumbing is correct. What will be required to return the message data?

Note. I understand that the client library is in beta testing, so this could be a hole that cannot yet be filled.

+4
source share
2 answers

echo "POST DATA: \ n"; print_r ($ posts);

your replacement:

$blogId = $blog->getId();
$post = $service->posts->listPosts($blogId);
print_r($post);
+2
source

( ) :

$id = $blog->getId();
$posts = $service->posts->listPosts($id, array("maxResults"=>5));
foreach($posts as $post) {
   echo "<br/>title:  ".$post->getTitle();
   echo "<br/>url:  ".$post->getUrl();
   echo "<br/>labels:  <pre>".print_r($post->getLabels(),TRUE)."</pre>";
   // etc.
}
0

All Articles