Skip to content

Instantly share code, notes, and snippets.

@damimolo
Last active January 2, 2016 14:49
Show Gist options
  • Save damimolo/37d0d0938aa821e004a2 to your computer and use it in GitHub Desktop.
Save damimolo/37d0d0938aa821e004a2 to your computer and use it in GitHub Desktop.
Google Cloud Datastore Error The library is this: https://github.com/google/google-api-php-client throw Google_Service_Exception at src/Google/Http/REST.php on line 75 Error calling POST https://www.googleapis.com/datastore/v1beta2/datasets/btspprt/lookup: (400) app s~btspprt cannot access app btspprt's data
<?php
/**
*
* The library is this: https://github.com/google/google-api-php-client
*
*
* throw Google_Service_Exception at src/Google/Http/REST.php on line 75
*
* Error calling POST https://www.googleapis.com/datastore/v1beta2/datasets/btspprt/lookup: (400) app s~btspprt cannot access app btspprt's data
*
*/
$creds = new Google_Auth_AssertionCredentials('__user__@developer.gserviceaccount.com', array(
'https://www.googleapis.com/auth/datastore',
'https://www.googleapis.com/auth/userinfo.email'
), file_get_contents('__public_key__-privatekey.p12'));
$client = new Google_Client();
$client->setAssertionCredentials($creds);
$datastore = new Google_Service_Datastore($client);
$AppId = '__application_id__';
$partitionId = new Google_Service_Datastore_PartitionId();
$partitionId->setDatasetId($AppId);
$partitionId->setNamespace('User');
$path = new Google_Service_Datastore_KeyPathElement();
$path->setId('__entity_id_as_integer__');
$path->setKind('User');
$key = new Google_Service_Datastore_Key();
$key->setPartitionId($partitionId);
$key->setPath($path);
$keys = array($key);
$readOptions = new Google_Service_Datastore_ReadOptions();
$readOptions->setReadConsistency("DEFAULT");
$lookupRequest = new Google_Service_Datastore_LookupRequest();
$lookupRequest->setKeys($keys);
$lookupRequest->setReadOptions($readOptions);
$datastore->datasets->lookup($AppId, $lookupRequest);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment