我正在尝试在Google Cloud环境中使用PHP App Engine中的Google Datastore。这个过程看起来不像云存储那样无缝,所以我将转而使用Datastore REST API。
文档中有一个地方,您可以在其中对Datastore API执行测试请求:https://cloud.google.com/datastore/docs/apis/v1beta2/datasets/lookup#try-it
我遇到的问题是,我想在没有OAuth的情况下完成这项工作(在上面的链接中有一个这样的选项)。但是,当我这样做时,我得到以下错误:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
从请求详细信息中,我可以看到以下HTTP请求签名:POST to https://www.googleapis.com/datastore/v1beta2/datasets/MY_PROJECT_ID/lookup?key={YOUR_API_KEY}
。
当我使用来自Google Cloud "APIs and Auth“凭证的服务器API密钥时,我得到如下信息:
{
"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"
}
}
我不太确定{YOUR_API_KEY}在这种情况下应该是什么,如果它不是服务器密钥。
我如何解决此问题并在没有OAuth的情况下访问Datastore API?
谢谢。
发布于 2015-10-11 18:32:26
我建议您使用这个库从PHP访问Datastore
https://github.com/tomwalder/php-gds
documentation
其他几个SO问题参考:
发布于 2015-10-10 02:56:51
Datastore API要求所有调用都有经过身份验证的用户,因此您将需要使用OAuth。
您可以使用API Client Library for PHP为您处理身份验证细节:https://developers.google.com/api-client-library/php/guide/aaa_overview
API密钥机制适用于不需要经过身份验证的用户的API。
https://stackoverflow.com/questions/33045098
复制相似问题