link: https://developers.google.com/datastore/docs/concepts/gql#using_literals_sample_code
<?php const APP_NAME='a-test-com'; const SERVICE_ACCOUNT_NAME=' 511908@developer.gserviceaccount.com '; $_PRIVATE_KEY=file_get_contents('data/34672c-privatekey.p12'); require_once 'google-api-php-client/Google_Client.php'; $client=new Google_Client(); $credentials=new Google_AssertionCredentials(SERVICE_ACCOUNT_NAME, array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/datastore' ), $_PRIVATE_KEY ); $client->setAssertionCredentials($credentials); $postBody=json_encode(array('gqlQuery'=>array('allowLiteral'=>true, 'queryString'=> "SELECT * FROM Guestbook WHERE __key__=key(Guestbook, 'default_guestbook')" ))); $httpRequest=new Google_HttpRequest('datastore/v1beta2/datasets/'.APP_NAME.'/runQuery', 'POST', null, $postBody); $head=array('content-type'=>'application/json; charset=UTF-8', 'content-length'=>Google_Utils::getStrLen($postBody) ); $httpRequest->setRequestHeaders($head); $httpRequest=Google_Client::$auth->sign($httpRequest); $result=Google_REST::execute($httpRequest); var_export($result); ?>
insert code: How to insert a record using the Datastore Viewer console using GQL
source share