如何使用 google-api-php-客户端获取 Android 应用的评论
How to get reviews for an Android App using google-api-php-client
我试过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);
帮我解决这个问题
$android_publisher = new Google_Service_AndroidPublisher($client);
$response = $android_publisher->reviews->listReviews('appname');
我做的对吗?
请给我一些资源来使用 php 编写 google api 调用。
我正在尝试在 Playstore 中获取我的应用程序的所有评论。
我正在尝试在 php 中进行此调用。
Google documentation
我从 运行 上面的代码得到的结果
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) {
}
}
当我做的时候
var_dump($client);
我得到的配置是
["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
}
这正常吗?
当你想访问一个googleapi。您需要在 Google 开发者控制台上创建一个应用程序。设置应用程序后,您将获得一个凭据文件。该文件在您的代码中用于访问 Google api。它告诉 google 和将要登录的用户谁是应用程序的所有者以及他们将请求什么数据。
您可以在下图中看到这一点。应用程序 google 分析 windows 想要请求用户访问 Google 分析数据。
凭据文件不允许您访问用户数据。登录应用程序并授予访问权限的用户将是授予数据访问权限的用户。
您可能已经获得了凭据文件,但您还必须获得 google 帐户的登录名和密码,该帐户可以访问数据,否则您将看不到任何内容。
TBH 我很惊讶你没有收到错误消息。万一您使用的是 service account,我从您的代码中看不到。您需要确保其设置正确才能访问数据,否则您也将无法看到它。
我试过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);
帮我解决这个问题
$android_publisher = new Google_Service_AndroidPublisher($client);
$response = $android_publisher->reviews->listReviews('appname');
我做的对吗?
请给我一些资源来使用 php 编写 google api 调用。 我正在尝试在 Playstore 中获取我的应用程序的所有评论。
我正在尝试在 php 中进行此调用。 Google documentation
我从 运行 上面的代码得到的结果
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) {
}
}
当我做的时候
var_dump($client);
我得到的配置是
["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
}
这正常吗?
当你想访问一个googleapi。您需要在 Google 开发者控制台上创建一个应用程序。设置应用程序后,您将获得一个凭据文件。该文件在您的代码中用于访问 Google api。它告诉 google 和将要登录的用户谁是应用程序的所有者以及他们将请求什么数据。
您可以在下图中看到这一点。应用程序 google 分析 windows 想要请求用户访问 Google 分析数据。
凭据文件不允许您访问用户数据。登录应用程序并授予访问权限的用户将是授予数据访问权限的用户。
您可能已经获得了凭据文件,但您还必须获得 google 帐户的登录名和密码,该帐户可以访问数据,否则您将看不到任何内容。
TBH 我很惊讶你没有收到错误消息。万一您使用的是 service account,我从您的代码中看不到。您需要确保其设置正确才能访问数据,否则您也将无法看到它。