Tuesday, October 4, 2011

Search Is Available In Google+ API

Google announced that Google+ API has search method.


Okay, Google APIs Perl Client can call search API. I don't need to change any code. It's great point of Google APIs Discovery Service. Then I can use search method. So I created a command-line sample.

I created two types. The one is with OAuth2, other is with Simple API Access.


With OAuth2

You can see the script at github.

Try like below

$ git clone git://github.com/comewalk/google-api-perl-client.git
$ cd google-api-perl-client
$ vim eg/plus/search.pl

You need to edit and . Your CLIENT ID and CLIENT SECRET is at API Console.

Okay, let's run the script

$ perl -I lib eg/plus/search.pl
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?client_id=&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=https://www.googleapis.com/auth/plus.me
Enter verification code: 

The script requires verification code. Please copy and paste the link from your console to your browser. Then your browser shows confirm page.

If you allow the access, you can get the code. Please paste the verification code to your console, then push return key.

You should see a result on your console like below.

$VAR1 = {
          'items' => [
                       {
                         'displayName' => 'Vic Gundotra'
                       },
                       {
                         'displayName' => 'Vic Ted'
                       },
                       {
                         'displayName' => 'Mark Lastiwka'
                       },
                       {
                         'displayName' => 'shreekrishna kc'
                       }
                     ]
        };

$VAR1 = {
          'items' => [
                       {
                         'object' => {
                                       'content' => 'Quirky and delicious recipes illustrated by artists from around the world? Yes, please!'
                                     }
                       },
                       {
                         'object' => {
                                       'content' => 'I am finally putting together a holiday cookie e-book. It will have plenty of great ideas, recipes, and pictures. Hoping to have it available on both kindle and as an ebook next week.'
                                     }
                       },
                       {
                         'object' => {
                                       'content' => 'I love this gorgeous fall weather! I'm gonna light my new gingerbread cookie candle and do some baking. I bought 3 pumpkins yesterday for some great fall recipes!'
                                     }
                       },
                       {
                         'object' => {
                                       'content' => 'Yesterday's Vegan MoFo post - Three Applelicious recipes: Apple Fritters, Apple Crisp, and an Apple Pie Hummus: http://blog.prairievegan.com/2011/10/mofoer-monday-appleicious-recipes-from.html'
                                     }
                       },
                       {
                         'object' => {
                                       'content' => 'Came home from work with crushing headache.  Slept for an hour and a half, and then made-- two (2) burgers for dinner, followed by lots (many) of Black Forest Chocolate Cookies.  Am feeling much better now.'
                                     }
                       },
                       {
                         'object' => {
                                       'content' => 'Saw this all over the net and couldn't find the original post till now ...'
                                     }
                       },
                       {
                         'object' => {
                                       'content' => 'These look delicious. I might even be able to make them!'
                                     }
                       },
                       {
                         'object' => {
                                       'content' => 'An ultimate collection of cookies recipe now available on iPhone and iPad http://goo.gl/mi2YP'
                                     }
                       },
                       {
                         'object' => {
                                       'content' => 'REALLY?'
                                     }
                       }
                     ]
        };

With Simple API Access

Also I create a sample.

Try like below

$ git clone git://github.com/comewalk/google-api-perl-client.git
$ cd google-api-perl-client
$ vim eg/plus/search_simple.pl

You need to edit <YOUR SIMPLE API ACCESS KEY> instead your Simple API Access key. Your key is at API console, too.

$ perl -I lib eg/plus/search_simple.pl

You don't need to get verification code. Yeah, it's simple. You will see same results as with OAuth2.


Conclusion

I didn't need to change any code in Google APIs Perl Client. Google APIs Discovery Service is awesome. (Or my code is awesome ;p)

These samples are using fields parameter. First result is from people.search method with fields="items/displayName". You can see displayName only. Seconde result is from activity.search method with fields="items/object/content". Fields parameter allows us to get only what you want.

I showed you how to use search method in Google+ API as a command-line script. If you want PSGI application, please feel free let me know at comment.

Enjoy!

1 comment:

  1. Hi, we're doing some work around this with www.affinitylive.com. Would be good to have a quick chat via email and compare notes & experiences. Feel free to drop me a line - geoff.mcqueen - at - affinitylive.com.

    ReplyDelete