Friday, December 2, 2011

Fwd: Checking Google APIs Discovery Service

I'm too late here. I'm a little busy in these days. In the near future, I'll build a Calendar API v3 sample. And I'll try to brush up this module as more useful.

I posted an entry on my blog. I just quoted that whole paragraph into this blog.


$ cp $services.txt $services_yesterday.txt
$ curl -s https://www.googleapis.com/discovery/v1/apis?fields=items/id | grep id > services.txt
$ cat services.txt
   "id": "adsense:v1"
   "id": "analytics:v2.4"
   "id": "analytics:v3"
   "id": "audit:v1"
   "id": "blogger:v2"
   "id": "books:v1"
   "id": "calendar:v3"
   "id": "customsearch:v1"
   "id": "discovery:v1"
   "id": "freebase:v1-sandbox"
   "id": "freebase:v1"
   "id": "groupssettings:v1"
   "id": "latitude:v1"
   "id": "moderator:v1"
   "id": "orkut:v2"
   "id": "pagespeedonline:v1"
   "id": "plus:v1"
   "id": "prediction:v1.2"
   "id": "prediction:v1.3"
   "id": "prediction:v1.4"
   "id": "shopping:v1"
   "id": "siteVerification:v1"
   "id": "taskqueue:v1beta1"
   "id": "tasks:v1"
   "id": "translate:v2"
   "id": "urlshortener:v1"
   "id": "webfonts:v1"
$ diff -bu $services_yesterday.txt $services.txt

I'm checking this everyday. I can find that Google add or remove APIs. You know how to use API Discovery resource like this :)


via blog.comewalk.com

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!

Wednesday, September 28, 2011

Google+ Perl Starter

Google+ has a page which listed some languages libraries.

Downloads

So, I created Google+ Perl Starter like other libraries.

http://code.google.com/p/google-plus-perl-starter/

The starter has two samples both PSGI application and command-line script.

If you're trying to implement your application written in Perl, please see the starter.

Enjoy!

Tuesday, September 27, 2011

Added Blogger API Sample

Updated Wed Sep 28 01:52:22 PDT 2011. Oops, I forgot a notice for everyone. You may need to request your quota for Blogger JSON API via Google APIs Console. Please check your console.


I added Blogger API sample on github. The sample shows blog object, post ids and URL for this blog.

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

You can try the sample like below.

 # Edit Simple API Access Key instead <YOUR API KEY>
 $ vim eg/blogger/cli_public_access.pl
 $ perl -I lib eg/blogger/cli_public_access.pl

Also, I updated sample wiki page.

Enjoy!

Monday, September 26, 2011

Added WebFonts API Sample

I added WebFonts API sample on github. The sample is listing available font families.

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

You can try the sample like below.

 # Edit Simple API Access Key instead <YOUR API KEY>
 $ vim eg/webfonts/cli_public_access.pl
 $ perl -I lib eg/webfonts/cli_public_access.pl

Also, I updated sample wiki page.

Enjoy!

Added Analytics API Sample

I added Analytics API sample on github. The sample is calling management.accounts.list API.

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

You can try the sample like below.

 # Edit Client ID and Client Secret
 $ vim eg/analytics/cli_private_access.pl
 $ perl -I lib eg/analytics/cli_private_access.pl

Also, I updated sample wiki page.

Oops, I forgot to mention changes.

  • Implemented nested resource.
    For example, Analytics API Discovery Resource Document has nested resource section like below.
     "resources": {
      "management": {
       "resources": {
        "accounts": {
         "methods": {
          "list": {
    
    Then this module supported nested resource for now :)

Thanks!

Thursday, September 22, 2011

Just Released!

Hello Perl mongers,

I'm happy to say this. I just pushed Google API Perl Client to github right now.

https://github.com/comewalk/google-api-perl-client/

If you try this module, you can run like below.

 $ git clone git://github.com/comewalk/google-api-perl-client.git
 $ cd google-api-perl-client
 $ perl -I lib eg/urlshortener/cli_public_access.pl

Also, I put psgi app.

 $ plackup eg/urlshortener/sample.psgi

If you embed this module in your application, you may need both Client ID and Client secret for private access. You can get Client ID and Client secret at Google APIs Console. Please replace "<YOUR CLIENT ID>" and "<YOUR CLIENT SECRET>" to your ones.

Samples list is following page at Google Project Hosting. I'll add more API samples later.

http://code.google.com/p/google-api-perl-client/wiki/Samples

Also, this module is using Google Project Hosting. The URL is below.

http://code.google.com/p/google-api-perl-client/

I'll update this blog for announcements of Google API Perl Client. If you're interested in this module, please add this blog to your feed reader.

If you have any questions or suggestions, please feel free let me know at Google Groups google-api-perl-client.

Enjoy!