Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The code in my last response works fine for me so I suspect you're facing an environmental problem. At any rate, I consulted with the owner of the Google PHP client library and he provided a better way to refresh the access token without resorting to calls to the internal refreshTokenWithAssertion() method. He suggested this technique:</p> <pre><code> $req = new apiHttpRequest(YOUR_URL); $val = $client-&gt;getIo()-&gt;authenticatedRequest($req); </code></pre> <p>The call to authenticatedRequest() takes care of refreshing the access token (with assertion credentials if they're set) as needed. I modified the code above to use this approach and it works fine for me. Note that both the old and new versions work for me so there's no functional difference but I think the new version is better because it avoids the internal call, uses the Google PHP client lib instead of curl to execute the request and results in much shorter, simpler code.</p> <pre><code>&lt;?php require_once 'apiClient.php'; // Define constants. const SERVICE_ACCOUNT_NAME = 'YOUR_SERVICE_ACCOUNT_NAME'; const KEY_FILE = 'key.p12'; const BUCKET = 'marc-us'; // Obtain service account credentials assertion. $client = new apiClient(); $key = file_get_contents(KEY_FILE); $client-&gt;setAssertionCredentials(new apiAssertionCredentials( SERVICE_ACCOUNT_NAME, array('https://www.googleapis.com/auth/devstorage.full_control'), $key) ); // Create HTTP request, authorize and execute. $req = new apiHttpRequest('http://commondatastorage.googleapis.com/' . BUCKET); $resp = $client::getIo()-&gt;authenticatedRequest($req); // Display results. print '&lt;h2&gt;Response:&lt;/h2&gt;' . $resp-&gt;getResponseBody(); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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