I’ve been working on a social media mash-up which requires me to pull content out of Blogger and Youtube. Google obviously has a mighty API, and they’ve released an extensive client library which you can use to connect to their services. Alas the PHP client is designed for the Zend framework, whereas my project was already committed to CakePHP.
Fortunately it was very simple to port the Google Data API into CakePHP (1.2.6). In fact it actually works out of the box, albeit with a couple configuration changes. There doesn’t seem to be any information available about this process online — so here are the steps I took.
2. Extract the contents of the zip file. Open the ‘library’ folder and grab the ‘Zend’ subfolder, drop this into your /app/vendors folder -> /app/vendors/Zend.
3. You need to add the vendors folder into your PHP include path. There are lots of ways to do this, although I didn’t want to hard code the strict path, so I edited the /app/webroot/index.php file as follows:
Define the vendors folder based on the existing environment variables:
4. At this point, you should be able to access the client libraries! You’ll notice under /app/vendors/Zend/Gdata there’s a series of library files — Docs.php, Photos.php, Youtube.php, and so on. I couldn’t find a Blogger.php library in my folder, but Zend has made a sample available here: http://framework.zend.com/svn/framework/standard/trunk/demos/Zend/Gdata/Blogger.php
5. Now open the appropriate controller file in your Cake app and call in whichever vendors you need:
And now you have full access to these services from your controller:
$this->blogger = new Blogger('blogger email address', 'blogger password');
That’s it! I won’t write about how to actually work with the API because there’s plenty of information already available. But this should be enough to get you up and running. If you run into any problems here, please leave comments below and I’ll update this article where needed.
Google Data API integration with CakePHP 1.2
I’ve been working on a social media mash-up which requires me to pull content out of Blogger and Youtube. Google obviously has a mighty API, and they’ve released an extensive client library which you can use to connect to their services. Alas the PHP client is designed for the Zend framework, whereas my project was already committed to CakePHP.
Fortunately it was very simple to port the Google Data API into CakePHP (1.2.6). In fact it actually works out of the box, albeit with a couple configuration changes. There doesn’t seem to be any information available about this process online — so here are the steps I took.
1. First, download the latest version of the client library from the Zend site: http://framework.zend.com/download/gdata
2. Extract the contents of the zip file. Open the ‘library’ folder and grab the ‘Zend’ subfolder, drop this into your /app/vendors folder -> /app/vendors/Zend.
3. You need to add the vendors folder into your PHP include path. There are lots of ways to do this, although I didn’t want to hard code the strict path, so I edited the /app/webroot/index.php file as follows:
Define the vendors folder based on the existing environment variables:
Later in the file, where ini_set(‘include_path’) is called, add this new VENDORS_DIR variable to the path:
4. At this point, you should be able to access the client libraries! You’ll notice under /app/vendors/Zend/Gdata there’s a series of library files — Docs.php, Photos.php, Youtube.php, and so on. I couldn’t find a Blogger.php library in my folder, but Zend has made a sample available here: http://framework.zend.com/svn/framework/standard/trunk/demos/Zend/Gdata/Blogger.php
5. Now open the appropriate controller file in your Cake app and call in whichever vendors you need:
App::import('Vendor', 'Zend/Gdata/Blogger');
App::import('Vendor', 'Zend/Gdata/Youtube');
And now you have full access to these services from your controller:
$this->blogger = new Blogger('blogger email address', 'blogger password');That’s it! I won’t write about how to actually work with the API because there’s plenty of information already available. But this should be enough to get you up and running. If you run into any problems here, please leave comments below and I’ll update this article where needed.