Getting Started with the Google Data PHP Client Library


Hello, my name is Trevor Johns, and I’m a software engineer
from the Google Data APIs team. The Google Data APIs allow you
to programmatically access various Google services, such as Blogger,
Google Calendar, your Gmail contacts list,
or even YouTube. I’m here today to help you
get started interacting with these APIs from
within your PHP applications. This video assumes
that you’re already familiar with the basics
of web development and PHP. It’ll also help
if you had past experience working with web services, though this
isn’t strictly required. Before we begin,
you’ll need three things– An HTTP Server, PHP, and the PHP Google Data
Client Library. I’ll go through each
of these briefly. Most hosting providers already
provide an HTTP server and PHP, but if you
haven’t already done so, I highly recommend installing
a copy locally for development purposes. Any HTTP server will do, provided that there’s support
executing PHP scripts. I recommend using
the Apache HTTP Server, which can be downloaded
from Once your HTTP server
is installed, you can download PHP
from OS-specific
installation instructions are posted
on each of these sites. While installing Apache and PHP are outside the scope
of this video, I’ll show you
how to quickly check to see if your installation
is properly set up. Simply create a file
that contains these two lines. The first is just
the standard PHP start tag, and the second
is the PHP info function, which, if you’ve done
PHP development before, you might know that it goes
and displays information about your PHP environment. If we save this
within our web root as, uh, say info.php… and then load it
within our browser… it should show information
about your PHP installation, such as the version,
any build commands you used, what your include path is. If you don’t get this page
and instead you just get the contents of the
info.php file you just saved, then you know something’s wrong,
and you’ll need to troubleshoot. Once you have
your HTTP server installed and running with PHP support, it’s time to download the
PHP Google Data Client Library. This is distributed as part of the Zend Framework
Open Source Project, available
at Zend Framework
includes a lot of components besides just what’s needed for
accessing the Google Data APIs. So, if you don’t want all
the overhead of Zend Framework or are already using
another web-development toolkit, you can download a lightweight
Google-only version of Zend Framework by going to
download/gdata. To demonstrate,
I’ll quickly go through the Zend Framework
installation process. So I’m just gonna go ahead
and open up a browser and go to
download/gdata and grab the tarball
from Latest Release. Once it finishes downloading, I’m just gonna go ahead
and extract it. Once this is done,
place the resulting folder somewhere safe and accessible
to your web server. Since on my system, both Apache and PHP
are installed in opt/local, I’m gonna go ahead
and place it there as well. On your system, you’ll probably
want to put it somewhere else. Finally, you’ll need to tell PHP
where to find Zend Framework. The best way to do this
is to modify your php.ini file. On my system, this is located
in opt/local/etc because I installed PHP
into opt/local. However, depending
on how you’ve installed PHP, it may be located
in another location, such as user/local/etc or C:PHP
if you’re on Windows. So I’m gonna go ahead
and open this up in Text Editor. All right? And find the line that begins
with “include_path.” All right? This is a colon-separated list
of various directories that PHP is going to search when
it’s looking up, um, libraries. I’m just gonna go ahead and add the path
where I stored Zend Gdata, so opt/local/ZendGdata
followed by /library. Now that I’ve updated
my php.ini, I just need to restart Apache so that PHP can pick up
the new changes. So I’m just gonna go ahead
and run Apache control restart. And then
it should be good to go. So I’m just gonna go ahead
and load php-a to get an interactive
PHP session, and I’m going to try and load
a file from Zend Framework. I’m gonna load
Zend/Loader.php, which should be there. If you don’t get any errors,
then everything’s good to go. If not, then you know
you need to troubleshoot. A good place to check,
if this happens, is to look at the info.php file
we created earlier. This will show you the include path
is currently in effect. So, if this is wrong, make sure that you’ve edited
the correct php.ini file and that the path you listed
is actually correct. If you’re deploying
to manage hosting, you might have direct access
to your php.ini file. If you’re hosting provider
has allowed it and if your hosting provider
is using Apache with mod-php, you can instead set PHP’s
configuration settings using an htaccess file. So to do this,
go ahead and create a new file. And then type the line,
“php_value include_path” and then in parentheses the path
to your Zend Gdata folder followed by /library. Then save this in your web root
as .htaccess and save it. I’m not gonna
actually save it because I’ve already edited
my php.ini, but otherwise,
this should work. Now that Zend Framework
is installed, let’s take a brief tour
of the client library. A useful page for this is the
Zend Framework API reference, available at
apidoc/core. Let’s go there now. All right, click on Zend_Gdata
in the upper-right-hand corner to switch to–to make that
the active package. And then you’ll notice on the
left there’s a list of classes within the–
within Zend Gdata. There’s five main types
of classes that you’ll normally be
interacting with– service classes,
query classes, feeds, entries,
and extension elements. Zend Gdata is an example
of a service class. Service classes are the heart
of the client library and serve to manage access to Google services
over the network. Zend Gdata is a generic
service class used for Blogger. Most of the services have
a dedicated service class, such as Zend Gdata at YouTube. Query classes
contain knowledge about the address scheme used
for the various services and are used to assist
in forming URLs. You can either allow the query
object to create a URL for you, or just pass the URL into the
query yourself if you know it. As before, Zend Gdata Query
is a generic query class, though many services
have specialized query classes, such as Zend Gdata YouTube. Feeds are returned
by service classes in response
to a network request, often using the help
of a query. Feeds are simply a collection
of entry objects, along with a small bit
of metadata to describe the collection. Zend Gdata Feed
is an example of this, and there is many subclasses
used for the various services. Entries,
as the name suggests, represent a logical collection
of data about something. This might be a blog post or a contact
or a calendar event. These are represented
by Zend Gdata Entry, and like Zend Gdata Feed, there’s many subclasses
used by each of the services. Finally, inside of entries
and feeds, extension elements are used to represent
individual pieces of data. For example, this might be
the owner of a blog, the title of a post,
or the date of a calendar event. These are represented
by subclasses of Zend Gdata App Extension. Now that you’re familiar
with the library, we’re going to write
a quick program to create and display posts
for Blogger. Let’s get started. So, to begin,
I’m gonna go and create a brand-new HTML file. I’ll go ahead and call this,
“Blogger PHP Demo.” And I’ll go ahead and put a nice
title at the top of the page. All right? And then I’m just gonna go ahead
and save this as blogger.php inside of my web root. At the very top, I’ll go ahead
and insert a block of PHP code to load
in Zend Gdata libraries. The very first thing
you should always load when using Zend Framework
is Zend/Loader.php. You can then use Zend Loader to load in any other
dependencies that you have. In this case,
we’re using Zend Gdata, Zend Gdata Query,
and Zend Gdata ClientLogin. Zend Gdata and Zend Gdata Query
I discussed earlier. Zend Gdata ClientLogin is used to go
and authenticate to Blogger. So, once that’s in place, I’ll
just go down here to the body, create another block
of PHP code, and authenticate to Blogger. So, again,
we’re using ClientLogin to actually authenticate. Uh, some other options
you might want to use here are auth 7.0 auth, which allow
you to go and log in without ever actually seeing
the user’s password, which is really great
for web apps, since it protects
the user’s security. Once that’s done,
we create an instance of the Zend Gdata service class
and call it Blogger Service. From there,
we’re just gonna go ahead and get a list
of all the user’s current blogs. So we create a new query. Um, this URL just happens to be
the Blogger Meta Feed, which lists all of the blogs
available for a user. This is documented
on And then we go
and use the Blogger service to go and fetch that feed. From there, we just go
and extract the first blogs, since that’s all
we care about right now, and we get the title,
the blog’s URL, and the URL of the feed
for that blog. Something to note here
is that title, while you’d normally think
of it as a string, is actually an XML element, and as such, it can have
various attributes, so you need to be sure to actually request
the text for the title, as opposed to anything else
that might be there. And this applies to any other
extension element as well. All right? And then we’re just gonna
go ahead and print this out. So, if we load this
in our browser… you can see that it successfully
fetched the first blog. And if I load it,
there’s the index page, and that looks good. So let’s go ahead and do something
a little more interesting. Let’s go and actually fetch all the blog posts
available on this blog. So, again,
we construct a new query, and we use the blog feed URL
that we extracted earlier. We then again use the service
to go and fetch this feed. And then we iterate through
every single entry in this feed, where it–and here every entry
represents a blog post. For each blog post, we go and extract the URL
for the blog post and the title and display them on screen
in a list. So, if we refresh
the page again… you’ll see it
successfully fetched all the blog posts available. All right? So, now that that’s done, let’s go and insert
some new posts into the blog. So I’m just gonna go
and create a form down here. This is just a normal post to the exact same page
we’re on right now. It has two inputs– a text field named “title” and a text area
named “body.” And you can see that
right here. Right now, this isn’t wired up
to do anything yet. So let’s fix that. So, right after
we fetch the first blog, we’ll check to see if there’s
anything in the forum. If the forum’s completely empty,
we won’t do anything, but if there are things
in the forum, we’ll go and, uh, create
a brand-new entry, populate the title
and the content using title
and content extension elements, and then just grab the title
and the body from the post and then use the service class
to insert that into the blog, using insert entry. If we save this one more time and then switch
back to the browser– I go ahead
and type in a title here. So, “Hello, World. This is my sample post.” And hit continue. You’ll see that the post
appears in the list. If I reload the blog’s index, it appears there. And if I click
on the post right here, it takes us to the page
dedicated to that post. If you’d like to learn more, check out
the PHP Getting Started Guide that accompanies this video. The URL is on your screen. The Zend Framework Manual
contains in-depth information about working
with Zend Framework modules, including this one. You can find this
at Finally, be sure to keep the Zend Framework API reference
I mentioned earlier on hand, available at
apidoc/core. I hope you got a good idea
how to get started. Thank you for watching
and happy coding.

Tags: , , , , , , , , , , , , ,

30 thoughts on “Getting Started with the Google Data PHP Client Library”

  1. sedative chunk says:

    Interesting all though it's a little overboard to use framework to make a few blog post along with retrieving them.

    I find the use of PHP to get you tube profile's and videos much more interesting and something I would like to try on my own website than this.

  2. skibbli says:

    I don't know how you can use a mac. the source is far too closed. but i guess everyone is a different user, and can make their own decisions.

  3. Roland Scull says:

    Umm, not all your viewers are native english. Could you maybe speak a little bit slower in your next tut?

  4. Roland Scull says:

    Yep, this does help. I'd like to mention, though, that I very rarely need aid like that.
    THX anyway! Roland

  5. relativityboy says:

    He speaks quickly, and his grammar is imperfect. Doubtless he's quite intelligent, but I've seen this in many true geeks. 🙂

  6. Konstantin Mirin says:

    Geek should always remain a human. He creates video to teach something, to share something, so speak better than, it's not as hard as develop the google base client lib 🙂
    Anyway, video is helpful, thanks!

  7. Dave Snyder says:

    Even your native English speaking viewers will have problems with this video ( myself included ). Maybe someone who's not so hopped up on coffee would be better.

  8. christinio says:

    Keep in mind not to lower your voice at the end of sentences and it will be ok 🙂

  9. reinheart767 says:

    good tutorial but why talk so fast 🙁 had to go back few time to figure out what you were trying to say… anyways got the info needed to start trying out the gdata. Thank you very much 🙂

  10. Sn4tched_it says:

    Gawd his voice is annoying!
    I'll have to watch this again (unfortunately) but ohh mann….

  11. 0xC0FF33 says:

    @ScullRoland Learn english, because I understand him very clearly and no: i am not native english

  12. Roland Scull says:

    Thanks for your very helpful advice, mate 😉

  13. PineHack says:

    They should get people who have good speaking skills to do these videos. Just about every GoogleDevelopers video I watch I either can't understand them, or in this case their voice just makes me want to get far, far away from the source it is coming from.

  14. Aswani Kumar says:

    i want gdata library independent of zend framework. all php developers dont use zend framework.

  15. Foxtrot64 says:

    dam using a mac made this 20x harder than what it needed to be ¬.¬

  16. Roland Scull says:

    @0xC0FF33 I am a native speaker, I don't understand him too well. I am ever so glad for you that you do 😉

  17. harsimranjit17 says:

    It looks like some body have speedup the pace of this video.. 🙂

  18. Judi Painted it says:

    What????? All I keep heading is PHHPS..THT…ITTT…IDONT GET IT…THTT

  19. Francesco Michelagnoli says:

    complicated speachless may…. nice application

  20. mrbrockpeters says:

    @ScullRoland Um the guy has to talk fast because he has to cover a lot of topics. I kinda always wondered why a lot of these web developer videos had guys that sounded like eunuchs on speed but I didn't fully understand until I had to make an instructional video myself. If you want to cover a lot of topics, you have to talk fast and the faster you talk the higher your voice becomes.

    Just be glad there's an instructional video for this period.

  21. efru1 says:

    @itnix hahhahaha…i love youtube comments

  22. Nadjib InfoMan says:

    Hey hey hey hold down, this guy isn't suitable to tell tutorials.

  23. TreacleMary says:

    Kwry == Query?

  24. Shaun Henderson says:

    Does this guy even need a GUI OS? Looks like DOS would be the go, looking at all the command line code he uses. Or is this just a bad feature of Macs? i.e. easier to use console than the GUI.

  25. J Lapp says:

    LOL Must be a windoze ONLY user 🙂 The power is ALWAYS in the CLS. GUI program most of the time give you some but not all access to the apps flags. Then there regex and piping I mean its just endless the things you can do in the command line you cant do in GUI. OK Im Done 🙂

  26. YoungMi says:

    What version of PHP does he use?

  27. dl m says:

    using xampp, had no errors at "require_once('ZendGdata/library/Zend/Loader.php');"
    but adding "Zend_Loader::loadClass('Zend_Gdata');
    Zend_Loader::loadClass('Zend_Gdata_ClientLogin');" gives multiple error messages.

  28. Jamil Al Nashash says:

    This video is awesome!

  29. Jamil Al Nashash says:

    This video is awesome! testing

Leave a Reply

Your email address will not be published. Required fields are marked *