Note that there are some explanatory texts on larger screens.

plurals
  1. POUpgrading to Google Fusion Tables to Google API V.1
    text
    copied!<p>I am upgrading a joomla component i once made for google fusion tables. I downloaded the new php api. But I have some doubts about how I should develop my site and some things with oauth.</p> <p>So my site reads the fusion tables and allows my (Joomla) users to change, delete or add data to any of those tables. So my question is, do I need a client login that is a web application type or a service account. It seems more logically to use the service account. If so how do I connect using php and the google php api framework.</p> <pre><code>$clientlogin_curl = curl_init(); curl_setopt($clientlogin_curl,CURLOPT_URL,'https://www.google.com/accounts/ClientLogin'); curl_setopt($clientlogin_curl, CURLOPT_POST, true); curl_setopt ($clientlogin_curl, CURLOPT_POSTFIELDS, "Email=".$username."&amp;Passwd=".$password."&amp;service=fusiontables&amp;accountType=GOOGLE"); curl_setopt($clientlogin_curl,CURLOPT_CONNECTTIMEOUT,2); curl_setopt($clientlogin_curl,CURLOPT_RETURNTRANSFER,1); $token = curl_exec($clientlogin_curl); curl_close($clientlogin_curl); $token_array = explode("=", $token); $token = str_replace("\n", "", $token_array[3]); </code></pre> <p>Above it is how I used to connect, but now I get quota exceed, because it is deprecated.</p> <p>I was reading this, <a href="https://code.google.com/p/google-api-php-client/wiki/OAuth2" rel="nofollow noreferrer">https://code.google.com/p/google-api-php-client/wiki/OAuth2</a>, and in the part of service accounts Fusion Tables is not mentioned. If not what should my redirect uri should be</p> <p>EDIT</p> <p>this is my code now</p> <pre><code>jimport('gft-jdc.oauth-php.src.Google_Client'); jimport('gft-jdc.oauth-php.src.contrib.Google_PlusService'); const CLIENT_ID = 'XXXXXXXXXXXXXXXXXXXXXXX7pu.apps.googleusercontent.com'; const SERVICE_ACCOUNT_NAME = 'XXXXXXXXXXXXXXXXXXXpu@developer.gserviceaccount.com'; const KEY_FILE = '/home/jdc/workspace/xxxxxxxxxxxxxxxprivatekey.p12'; class ClientLogin { public static function getAuthToken($username, $password) { $client = new Google_Client(); $client-&gt;setApplicationName("API Project"); var_dump(CLIENT_ID); var_dump(KEY_FILE); $client-&gt;setClientId(CLIENT_ID); // Set your cached access token. Remember to replace $_SESSION with a // real database or memcached. if (isset($_SESSION['token'])) { $client-&gt;setAccessToken($_SESSION['token']); } // Load the key in PKCS 12 format (you need to download this from the // Google API Console when the service account was created. $key = file_get_contents(KEY_FILE); $client-&gt;setAssertionCredentials(new Google_AssertionCredentials( SERVICE_ACCOUNT_NAME, array('https://www.googleapis.com/auth/fusiontables'), $key) ); $client-&gt;authenticate(); if ($client-&gt;getAccessToken()) { $_SESSION['token'] = $client-&gt;getAccessToken(); } $token = $_SESSION['token']; var_dump($token); return $token; } } </code></pre> <p>I get this error</p> <p><img src="https://i.stack.imgur.com/YPy1J.png" alt="enter image description here"></p> <p><strong>Solution</strong>, I just solved this last problem, you dont need $client->authenticate()</p> <p>Here is a solution <a href="https://stackoverflow.com/questions/13506930/how-to-get-oauth2-access-token-with-google-api-php-client">How to get OAuth2 access token with Google API PHP client?</a></p> <pre><code>if ($client-&gt;getAuth()-&gt;isAccessTokenExpired()) { $client-&gt;getAuth()-&gt;refreshTokenWithAssertion(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload