authenticating a service account to call a Google API with JavaScript client library
<p>I want to make <b>JSON-RPC</b> calls from localhost (WAMP environment) to the <a href="https://developers.google.com/fusiontables/docs/v2/getting_started" rel="noreferrer">Google FusionTables API</a> (and a couple of other APIs) using the <a href="https://developers.google.com/api-client-library/javascript/" rel="noreferrer">Google Client Library for JavaScript</a></p>

<h2>Steps I have taken:</h2>

<ol>
<li>setup a project on the <a href="https://console.developers.google.com/apis/dashboard" rel="noreferrer">Google Developer Console</a></li>
<li>enabled the FusionTables API</li>
<li>created a service account and downloaded the JSON file.</li>
<li>successfully loaded the JS client library with the auth package: <code>gapi.load('client:auth2', initAuth);</code></li>
<li>constructed the init method parameter the following 3 ways:

<ul>
<li>the downloaded JSON verbatim</li>
<li>the downloaded JSON modified to include the scope</li>
<li>just the client ID and scope</li>
</ul></li>
<li>tried (and failed) to initialize the GoogleAuth instance: <code>gapi.auth2.init(params)</code></li>
</ol>

<pre>

    function failed(reason) {
        console.log(reason);
    }
    gapi.load('client:auth2', initAuth);

    function initAuth() {

        var APIkey = 'MY API KEY';
        gapi.client.setApiKey(APIkey); //I understand this to be unnecessary with authorized requests, included just for good measure

        var GDTSAKey = 'MY SERVICE ACCOUNT KEY';
        var scopes = 'https://www.googleapis.com/auth/fusiontables';
        gapi.auth2.init({
            client_id: "101397488004556049686",
            scope: 'https://www.googleapis.com/auth/fusiontables'
        }).then(signin, failed("couldn't initiate"));
        //passing the downlaoded JSON object verbatim as parameter to init didn't work either
    } //initAuth()

    function signin() {
        gapi.auth2.getAuthInstance().signIn().then(makeAPIcall), failed("couldn't sign-in");
    }

    function makeAPIcall(){
        gapi.client.load('fusiontables', 'v2', function(){
            var tableId = '1PSI_...';
            var table = gapi.client.fusiontables.table.get(tableId);
            document.querySelector("#result").innerHTML = table;            
        });
    }

</pre>

<p>based on <a href="https://developers.google.com/api-client-library/javascript/samples/samples#authorizing-and-making-authorized-requests" rel="noreferrer" title="Authorizing and Making Authorized Requests">JS client library >> Samples</a></p>

<p>the <code>gapi.auth2.init</code> method invokes the second callback (which I understand to be an error handler): failed("couldn't initiate"), but then, curiously, I also get `couldn't sign in' which could only have originated from within the provided success handler. What's going on? How do I get this to work?</p>

<p><em>Note:</em> I am only willing to try the CORS/xhr, if there is no way to do it with JS client lib.</p>