Is there an example using a service account to access Fusion Tables?

419 views
Skip to first unread message

Stefan Oderbolz

unread,
Apr 27, 2012, 4:49:07 AM4/27/12
to google-api...@googlegroups.com
Hi there,

I got the service account example using the Prediction API to work, but I don't really know how to adapt the example to access Fusion Tables. Is there an example? And if there is not, what is the easiest way to just retrieve the access_token? I tried something like that:

$client = new apiClient();
$client->setClientId(CLIENT_ID);
$client->setScopes('https://www.googleapis.com/auth/fusiontables');
//add key
$key = file_get_contents(KEY_FILE);
$client->setAssertionCredentials(new apiAssertionCredentials(
  SERVICE_ACCOUNT_NAME,
  array('https://accounts.google.com/o/oauth2/token'),
  $key)
);
$client->authenticate();
print $client->getAccessToken();
 
Am I on the right track? With this code I get an error about a missing "redirect_uri", but I don't think I need that parameter for a service account, so probably my request is wrong. Any help appreciated.

Regards Stefan

Mr. Moses

unread,
May 21, 2012, 1:13:24 PM5/21/12
to google-api...@googlegroups.com
I had some trouble getting this working as well (with Google Cloud Storage). I got it working, but am not sure if this is the correct usage of the library.

Replace $client->authenticate(); with $client::$auth->refreshTokenWithAssertion();

Stefan Oderbolz

unread,
May 21, 2012, 3:52:10 PM5/21/12
to google-api...@googlegroups.com
Thank you very much! This solved my problem. In the meantime I used an ugly solution where I "hijacked" the UrlShortener service to get the proper authentication. But this is much cleaner and exactly what I was looking for.

Regards Stefan

Drywall

unread,
Aug 8, 2012, 1:09:46 PM8/8/12
to google-api...@googlegroups.com
Thanks for this. I'm really struggling with the lack of Fusion Tables API documentation/support in this PHP library.

Unfortunately for me the "apiAssertionCredentials" class doesn't seem to exist, so the aforementioned code is still failing for me. I've done a search through the entirety of the codebase for this project and found no mention of apiAssertionCredentials.

Ben

Stefan Oderbolz

unread,
Aug 8, 2012, 3:48:09 PM8/8/12
to google-api...@googlegroups.com
Hi Ben,

I just checked their project and apparently in the meantime they changed the naming of the classes and the library in general. 
The new "apiClient" is now called "Google_Client" and the "apiAssertionCredentials" is "Google_AssertionCredentials", so the example would be something like that (not tested):

require_once 'path/to/Google_Client.php';

$client = new Google_Client();
$client->setClientId(CLIENT_ID);

//add key
$key = file_get_contents(KEY_FILE);
$client->setAssertionCredentials(new Google_AssertionCredentials(
  SERVICE_ACCOUNT_NAME,
  array('https://www.googleapis.com/auth/fusiontables'),
  $key)
);
$client::$auth->refreshTokenWithAssertion();
print $client->getAccessToken();

Unfortunately they didn't change the wiki entries (http://code.google.com/p/google-api-php-client/wiki/OAuth2) according to the new naming :(

Regards Stefan

Chirag Shah

unread,
Aug 8, 2012, 4:03:54 PM8/8/12
to google-api...@googlegroups.com
Hey,

Good catch Stefan, I've updated the OAuth documentation to reflect the renaming.
That is correct, we've renamed the client library with proper name-spacing to avoid conflicts with other libraries.

Stefan Oderbolz

unread,
Aug 8, 2012, 4:17:34 PM8/8/12
to google-api...@googlegroups.com
Oh, wow that was fast, but there are other not updates pages:

Chirag Shah

unread,
Aug 8, 2012, 4:23:02 PM8/8/12
to google-api...@googlegroups.com
The rest of the documentation is for the release build of the client library:

The current release build isn't namespaced, but that will be changing soon.

Service accounts are currently under development, so that bit of documentation requires
people to download the latest version from trunk (bleeding edge).
Reply all
Reply to author
Forward
0 new messages