Wednesday, October 26, 2011

Added AdSense Management API sample

I just added AdSense Management API sample in github


https://github.com/comewalk/google-api-perl-client/blob/master/eg/adsense

This sample is inspired by a thread in google-api-python-client group. Thanks!



So, you can try the sample like below.

 $ git clone git://github.com/comewalk/google-api-perl-client.git
 $ cd google-api-perl-client.git
 # Edit Client ID and Client Secret in client_secrets.json
 $ vim eg/adsense/client_secrets.json
 $ ls eg/adsense/*.pl | xargs -n 1 perl -I lib

Then you will see like this.

Ad client for product xxxx with ID aaa-bbb-1234567890 was found
  Supports reporting: true and 'Yes' or 'No'
Done
Wide character in print at eg/adsense/adunits_list.pl line 39.
Ad unit with code NNNNNNNNNN, name 300x250, 作成済み 10/06/07 and status INACTIVE was found
Done
Custom channel with code NNNNNNNNN and name http://www.s14u.info/mt/ was found
Done
== aaa-bbb-1234567890 ==
DATE PAGE_VIEWS AD_REQUESTS AD_REQUESTS_COVERAGE CLICKS AD_REQUESTS_CTR COST_PER_CLICK AD_REQUESTS_RPM EARNINGS
2011-01-24 1 1 1 0 0 N/A 0 0
2011-01-29 1 1 1 0 0 N/A 0 0
2011-03-31 2 2 1 0 0 N/A 0 0
2011-06-07 1 1 1 0 0 N/A 0 0
2011-06-09 1 1 1 0 0 N/A 0 0
2011-07-12 2 2 1 0 0 N/A 0 0
2011-08-04 18 18 1 0 0 N/A 0 0
2011-08-28 10 10 1 0 0 N/A 0 0
2011-08-29 11 11 1 0 0 N/A 0 0
2011-08-30 4 4 1 0 0 N/A 0 0
2011-09-08 1 1 1 0 0 N/A 0 0
2011-09-16 3 3 1 0 0 N/A 0 0
2011-09-26 2 2 1 0 0 N/A 0 0
Done
URL channel with URL pattern comewalk.example.com was found
Done

Also, I updated sample wiki page.


Enjoy!

Sunday, October 23, 2011

Support client_secrets.json file format

Joe Gregorio mentioned google-api-python-client has supported ClientSecrets at his Google+.


Then google-api-perl-client has supported the format.


Please see following sample.

https://github.com/comewalk/google-api-perl-client/blob/master/eg/plus/plus_with_clientsecrets.pl


my $client = Google::API::Client->new;
my $service = $client->build('plus', 'v1');

my $file = "$FindBin::Bin/client_secrets.json";
my $auth_driver = Google::API::OAuth2::Client->new_from_client_secrets($file, $service->{auth_doc});


See Also:

The file format is (loosely) defined here:
http://code.google.com/p/google-api-python-client/wiki/ClientSecrets
The oauth2client/google-api-python-client support is explained here:
http://code.google.com/p/google-api-python-client/wiki/ClientSecretsSupport

Thank you for your waiting for a while. I was a little bit busy in these days for YAPC::Asia Tokyo 2011, Google Developer Day 2011 Tokyo and so on.


Enjoy!

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!