Today I get this lovely email from google telling me all about the availability of the new Google+ Platform API. So naturally I have to check it out! For a while I have been using facebook and twitter feeds as simplistic blogs for some of my sites, but for my personal site, I would love to just use Google+.
I've created a simple example of how to setup and read your own public Google+ feeds.
Enabling API access and getting your API Key
- Head over to the APIs Console.
- Select Services
- Enable the Google+ API services. Without this you will not be able to access your feeds.
- Select API Access
- Under Simple API Access, grab your API Key. Hang onto this as we will need it to access any of the API services.
Getting your Google+ ID
If you don't already know where this is located, head on over to Google+, click on your image in the upper right, and click Profile. In the address bar, it will now have a link like
https://plus.google.com/106670447018211124292
Accessing your activity stream
Now that you have your ID and Key, you can go to the url of your stream. Your stream URL will look like this
https://www.googleapis.com/plus/v1/people/106670447018211124292/activities/public?key=[API Key]
Parsing this stuff in PHP
Thankfully all the responses are in JSON which makes it really easy to read the data. Each item is inside of items.
$id = '106670447018211124292';
$key = 'YOUR KEY HERE';
$feed = json_decode(file_get_contents('https://www.googleapis.com/plus/v1/people/'.$id.'/activities/public?key='.$key));
foreach ($feed->items as $item) {
echo '<h2>'.$item->title.'</h2>'
.'<i>'.date('F jS Y @ H:i:s',strtotime($item->published)).'</i>'
.'<p>'.$item->object->content.'</p>'
.'<br /><br />';
}
And now we can access our public junk! This feed contains some additional information other than just the title and content. Like if you entered a url, it will attach the url to it inside of object.