简体   繁体   中英

Set up Google Cloud Datastore with PHP runtime

I am developing the backend for an app using App Engine with PHP runtime and Google Cloud Datastore.
I have set up a local development for App Engine and I am using the gcd tool for local Datastore.
When I send requests to online Datastore it works.
Unfortunately, when I'm sending any request to local Datastore I get the following error in the browser:

Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling
POST http://localhost:8081/datastore/v1beta2/datasets/project-id/allocateIds: (400)
unsupported content-type: application/json; charset=UTF-8' in G:\Programs\Google\Cloud 
SDK\project-id\default\Google\Http\REST.php:79 Stack trace: #0 G:\Programs\Google\Cloud   
SDK\project-id\default\Google\Http\REST.php(44): Google_Http_REST::decodeHttpResponse(
Object(Google_Http_Request)) #1 G:\Programs\Google\Cloud SDK\project-id\default\Google
\Client.php(503): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_
Request)) #2 G:\Programs\Google\Cloud SDK\project-id\default\Google\Service\Resource.
php(195): Google_Client->execute(Object(Google_Http_Request)) #3 G:\Programs\Google\
Cloud SDK\project-id\default\Google\Service\Datastore.php(153): Google_Service_
Resource->call('allocateIds', Array, 'Google_Service_...') #4 G:\Programs\Google\Cloud 
SDK\project-id\default\DatastoreService.php in G:\Programs\Google\Cloud SDK\
project-id\default\Google\Http\REST.php on line 79

and in the gcd I get the following error:

Sep 17, 2014 8:24:07 PM com.google.apphosting.client.serviceapp.BaseApiServlet doPost
INFO: ApiServlet POST
Sep 17, 2014 8:24:07 PM com.google.apphosting.client.serviceapp.BaseApiServlet doCall
INFO: unsupported content-type: application/json; charset=UTF-8
Sep 17, 2014 8:24:07 PM com.google.apphosting.client.serviceapp.BaseApiServlet 
writeErrorResponse
SEVERE: INVALID_ARGUMENT: unsupported content-type: application/json; charset=UTF-8

I have tried changing content-type in Google/Service/Resource.php line 171 but nothing seems to work.
Any idea on how can I fix this?

Unfortunately, Google Cloud Datastore's local development server ( gcd.sh ) does not currently support JSON as a transport (which is used by the PHP client library).

A workaround is to create a second project you use only for testing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM