0

I tried google-api-php-client

<?php 

require_once 'google-api-php-client-2.2.2\vendor\autoload.php';

putenv('GOOGLE_APPLICATION_CREDENTIALS=client_secret.json');

$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(Google_Service_AndroidPublisher::ANDROIDPUBLISHER);

$android_publisher = new Google_Service_AndroidPublisher($client);
$response = $android_publisher->reviews->listReviews('appname');   

echo "<pre>";
var_dump($response);

And help me with this

$android_publisher = new Google_Service_AndroidPublisher($client);
$response = $android_publisher->reviews->listReviews('appname');

am I doing it right?

please give me some resources to write a google api call using php. I am trying to get the all reviews for my app in playstore.

I am trying make this call in php. Google documentation

Library I am Using

Result I Got from running the code above

object(Google_Service_AndroidPublisher_ReviewsListResponse)#70 (10) {
  ["collection_key":protected]=>
  string(7) "reviews"
  ["pageInfoType":protected]=>
  string(40) "Google_Service_AndroidPublisher_PageInfo"
  ["pageInfoDataType":protected]=>
  string(0) ""
  ["reviewsType":protected]=>
  string(38) "Google_Service_AndroidPublisher_Review"
  ["reviewsDataType":protected]=>
  string(5) "array"
  ["tokenPaginationType":protected]=>
  string(47) "Google_Service_AndroidPublisher_TokenPagination"
  ["tokenPaginationDataType":protected]=>
  string(0) ""
  ["internal_gapi_mappings":protected]=>
  array(0) {
  }
  ["modelData":protected]=>
  array(0) {
  }
  ["processed":protected]=>
  array(0) {
  }
}

when I did

var_dump($client);

Config I got is

["config":"Google_Client":private]=>
  array(23) {
    ["application_name"]=>
    string(9) "php_level"
    ["base_path"]=>
    string(26) "https://www.googleapis.com"
    ["client_id"]=>
    string(0) ""
    ["client_secret"]=>
    string(0) ""
    ["redirect_uri"]=>
    NULL
    ["state"]=>
    NULL
    ["developer_key"]=>
    string(0) ""
    ["use_application_default_credentials"]=>
    bool(true)
    ["signing_key"]=>
    NULL
    ["signing_algorithm"]=>
    NULL
    ["subject"]=>
    NULL
    ["hd"]=>
    string(0) ""
    ["prompt"]=>
    string(0) ""
    ["openid.realm"]=>
    string(0) ""
    ["include_granted_scopes"]=>
    NULL
    ["login_hint"]=>
    string(0) ""
    ["request_visible_actions"]=>
    string(0) ""
    ["access_type"]=>
    string(6) "online"
    ["approval_prompt"]=>
    string(4) "auto"
    ["retry"]=>
    array(0) {
    }
    ["cache_config"]=>
    array(0) {
    }
    ["token_callback"]=>
    NULL
    ["jwt"]=>
    NULL
  }

Is this normal?

  • What error are you getting? – Linda Lawton - DaImTo Nov 20 '18 at 10:45
  • @DalmTo I an getting an empty result. object(Google_Service_AndroidPublisher_ReviewsListResponse)#70 ["collection_key":protected]=> string(7) "reviews" ["pageInfoType":protected]=> string(40) "Google_Service_AndroidPublisher_PageInfo" ["pageInfoDataType":protected]=> string(0) "" ["reviewsType":protected]=> string(38) "Google_Service_AndroidPublisher_Review" ["reviewsDataType":protected]=> string(5) "array" ["tokenPaginationType":protected]=> string(47) "Google_Service_AndroidPublisher_TokenPagination" ["tokenPaginationDataType":protected]=> .. – Harold Gomez Nov 20 '18 at 10:48
  • That looks like a response object to me – Linda Lawton - DaImTo Nov 20 '18 at 10:51
  • but it's empty!!! The app that I am working on does have reviews, Is my code correct ? I think that I made some mistake, is this how it's done? @DalmTo – Harold Gomez Nov 20 '18 at 10:55
  • If your code is returning a response then it must be correct or you would get an error response. Being empty means that there is no data to be found. Not that i am sure there is no data have you tried $response ->getReviews()? – Linda Lawton - DaImTo Nov 20 '18 at 11:27
  • array(0) { } I got an empty array. but I have a doubt on credentials I will update question. @DalmTo – Harold Gomez Nov 20 '18 at 11:42
  • Then which ever user you are logging in with probably doesnt have access to the data. – Linda Lawton - DaImTo Nov 20 '18 at 11:51
  • @DalmTo I feel the same too, but I am not in control of the account. – Harold Gomez Nov 20 '18 at 12:01
  • Well if you are not in control of the account how are you logging in? You can only access data you have access to. Who ever runs the application and logs in must have access to the data you are trying see. – Linda Lawton - DaImTo Nov 20 '18 at 12:05
  • @DalmTo I am working for someone they are providing the credential files. – Harold Gomez Nov 20 '18 at 12:11
  • The credeitnals file just denotes the application to Google. It has nothing to do with the user you are logging in with that needs to have access to the data you are trying to access. – Linda Lawton - DaImTo Nov 20 '18 at 12:18

1 Answers1

0

When you want to access a google api. You need to create an application on Google Developer console. Once your application is set up you will get a credentials file. This file is used in your code to access a Google api. It tells google and the user who will be logging in who the owner of the application is and what data they will be requesting.

You can see this in the following picture. The application google analytics windows would like to request access of the user for Google analytics data.

enter image description here

The credentials file does not give you access to a users data. The user who logs into the application and grants access will be the one who grants the access to the data.

You may have been given a credentials file but you must also be given a login and password to a google account that has access to the data or your not going to be able to see anything.

TBH i am surprised you are not getting an error message. In the off chance that you are using a service account which i cant see from your code. You need to make sure that its set up properly to have access to the data or you will also not be able to see it.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • 1
    I think the service account that I got does not have right permissions – Harold Gomez Nov 20 '18 at 12:30
  • I am surprised you are not getting an error but i dont have access to a play developer account so cant test it. – Linda Lawton - DaImTo Nov 20 '18 at 12:31
  • I guess the owner of the app created service account , except the service account I got is not configured properly to get right authorization. https://cloud.google.com/iam/docs/creating-managing-service-account-keys – Harold Gomez Nov 20 '18 at 12:51