Search code examples
phpgoogle-app-enginegoogle-apigoogle-cloud-datastoregoogle-php-sdk

Google Cloud Datastore PropertyFilter Error


I'm using the google apis php sdk and trying to access some data from my google cloud datastore. I'm authenticating no problem at this point, but am getting an error during my query. I pretty much look through the code in the sdk to implement it, since documentation is null, but there's nothing that hints at why i'm getting this error.

Here's my code:

    $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);

Here's the error i'm getting:

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

Where do I add this kind google is asking for??


Solution

  • Solution:

    I did need to use the $query->setKinds() method as Ed Davisson suggested, however it cannot just take a string. You need to give it the Google_Service_Datastore_KindExpression Object

    Example:

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