0

I'm trying to use Google Datastore from PHP App Engine in the Google Cloud environment. The process doesn't appear to be as seamless as Cloud Storage, so instead I'm going to use the Datastore REST API.

There's a place in the docs where you can do a test request to the Datastore API: https://cloud.google.com/datastore/docs/apis/v1beta2/datasets/lookup#try-it

The problem I'm having is that I want to do this without OAuth (there's an option for this at the above link). However, when I do, I get the following error:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

From the request details I see the following HTTP request signature: POST to https://www.googleapis.com/datastore/v1beta2/datasets/MY_PROJECT_ID/lookup?key={YOUR_API_KEY}.

When I use my Server API key from the Google Cloud "APIs and Auth" Credentials, I get this:

{
  "error": {
    "errors": [
      {
        "domain": "global",
        "reason": "authError",
        "message": "HTTP Basic Authentication is not supported for this API",
        "locationType": "header",
        "location": "Authorization"
      }
    ],
    "code": 401,
    "message": "HTTP Basic Authentication is not supported for this API"
  }
}

I'm not quite sure what {YOUR_API_KEY} is supposed to be in this case if it's not the server key.

How can I fix this and access the Datastore API without OAuth?

Thanks.

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
ObiHill
  • 11,448
  • 20
  • 86
  • 135

2 Answers2

1

I recommend you use this library to access Datastore from PHP

https://github.com/tomwalder/php-gds

  • It has documentation
  • It supports native Protocol Buffer access - which does not need the authentication cycle used in the REST or JSON services (i.e. It's much easier and quicker to get up and running)
  • AND the JSON API for remote use
  • It supports local (development) datastore

A couple of other SO question references:

Community
  • 1
  • 1
Tom
  • 1,563
  • 12
  • 12
  • Disclaimer: I am the author! – Tom Oct 11 '15 at 10:32
  • Thanks Tom, I actually stumbled on this a while ago, but I have no idea how to install it. Can you provide some instructions for folks that don't use Composer? – ObiHill Oct 12 '15 at 11:17
  • Thanks. Much appreciated. Just don't have the patience to learn more tech just to install a PHP script – ObiHill Oct 13 '15 at 03:03
0

The Datastore API requires an authenticated user for all calls, so you will need to use OAuth.

You may be able to use the API Client Library for PHP to handle the authentication details for you: https://developers.google.com/api-client-library/php/guide/aaa_overview

The API key mechanism is for APIs that don't require an authenticated user.

Ed Davisson
  • 2,927
  • 11
  • 11
  • Thanks. The links on the page you referred to are returning 404 errors. I think I will explore Parse at this point. I wanted to keep it in the Google family but this is just too much stress for a simple key-value store. – ObiHill Oct 09 '15 at 19:39