【问题标题】:Google Cloud Datastore PropertyFilter ErrorGoogle Cloud Datastore PropertyFilter 错误
【发布时间】:2015-08-21 01:32:50
【问题描述】:

我正在使用 google apis php sdk 并尝试从我的 google 云数据存储中访问一些数据。此时我的身份验证没有问题,但在我的查询过程中出现错误。我几乎通过 sdk 中的代码来实现它,因为文档是空的,但是没有任何迹象表明我为什么会收到这个错误。

这是我的代码:

    $run_query = new Google_Service_Datastore_RunQueryRequest;                                                                                                                 15  
    $query     = new Google_Service_Datastore_Query;
    $query->setKinds(array("views"));                                                                                                                  16  
    $query_filter = new Google_Service_Datastore_Filter;                                                                                                                       17  
    $query_property_filter = new Google_Service_Datastore_PropertyFilter;                                                                                                      18 
    $query_property_filter->setOperator('EQUAL');                                                                                                                              19  
    $query_property_ref    = new Google_Service_Datastore_PropertyReference;                                                                                                   20 
    $query_property_ref->setName('_IS_ACTIVE');                                                                                                                                21  
    $query_property_val    = new Google_Service_Datastore_Value;                                                                                                               22  
    $query_property_val->setBooleanValue(true);                                                                                                                                23 
    $query_property_filter->setProperty($query_property_ref);                                                                                                                  24 class Google_Model implements ArrayAccess
    $query_property_filter->setValue($query_property_val);                                                                                                                     25 {
    $query_filter->setPropertyFilter($query_property_filter);                                                                                                                  26   
    $query->setFilter($query_filter);                                                                                                                                          27    
    $run_query->setQuery($query);                                                                                                                                              28     null. 
                                                                                                                                                                               29   
    $views = $datastore->datasets->runQuery('my-project-id', $run_query);

这是我得到的错误:

Google_Service_Exception [ 500 ]: Error calling POST https://www.googleapis.com/datastore/v1beta2/datasets/my-project-id/runQuery: (400) kind is required for filter: _IS_ACTIVE

我在哪里添加这个kind google 要求的??

【问题讨论】:

    标签: php google-app-engine google-api google-cloud-datastore google-php-sdk


    【解决方案1】:

    数据存储区查询中的过滤器通常要求您指定要检索的实体类型。您可以将其设置为:

    $query->setKinds(array('views'))
    

    【讨论】:

    • 我尝试添加它,但我仍然收到错误消息。更新示例以反映代码的变化。
    【解决方案2】:

    解决方案:

    我确实需要按照 Ed Davisson 的建议使用 $query->setKinds() 方法,但它不能只接受一个字符串。你需要给它Google_Service_Datastore_KindExpression Object

    例子:

    $views_kind= new Google_Service_Datastore_KindExpression;
    $views_kind->setName("views");
    $query->setKinds(array($views_kind));
    

    【讨论】:

    • 啊,抱歉,埃里克。感谢您发布更正的答案。
    • 感谢您为我指明正确的方向。通常,图书馆很容易通过阅读代码来弄清楚要做什么。这比平时更令人困惑。我还查看了使用开发人员仪表板时发布的 json 对象,这有助于我更详细地了解这些查询对象。
    猜你喜欢
    • 2016-11-16
    • 1970-01-01
    • 2014-01-26
    • 1970-01-01
    • 2020-12-30
    • 2023-03-20
    • 2021-10-31
    • 2017-04-13
    • 2020-01-22
    相关资源
    最近更新 更多