[英]Google Play Store reviews API in PHP
Currently I am trying to get reviews from https://play.google.com/store/apps/details?id=com.rosterelf.android.phone&hl=en by following https://developers.google.com/android-publisher/api-ref/rest/v3/reviews/list documentation.目前我正在尝试通过关注Z5E056C500A1C4B6A7110B50D从https://play.google.com/store/apps/details?id=com.rosterelf.android.phone&hl=en获得评论/api-ref/rest/v3/reviews/list文档。
I am using the PHP (cURL) method but I am keep getting an error saying --- Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential.
我正在使用 PHP (cURL) 方法,但我不断收到错误消息 ---
Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential.
Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential.
Below are my steps what I have done / tried so far.以下是我到目前为止所做/尝试的步骤。
Created one
Api KEY
,OAuth 2.0 Client ID
andService Account
inGoogle Developer Console
.在
Google Developer Console
中创建了一个Api KEY
、OAuth 2.0 Client ID
和Service Account
。
Enabled the
Google Play Android Developer API
andGoogle Play Custom App Publishing API
too.也启用了
Google Play Android Developer API
和Google Play Custom App Publishing API
。
Going at my browser https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&redirect_uri=REDIRECT-URI&client_id=CLIENT-ID
进入我的浏览器https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&redirect_uri=REDIRECT-URI&client_id=CLIENT-ID
It gives me the
code
in response and then to be able to getaccess_token
, I am using below PHP cURL code which is also working fine.它给了我响应
code
,然后能够获取access_token
,我在下面使用 PHP cURL 代码,它也可以正常工作。
<?php
$client_id = 'CLIENT-ID';
$redirect_uri = 'REDIRECT-URL';
$client_secret = 'CLIENT-SECRET';
$code = 'CODE';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://accounts.google.com/o/oauth2/token");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'code' => $code,
'client_id' => $client_id,
'client_secret' => $client_secret,
'redirect_uri' => $redirect_uri,
'grant_type' => 'authorization_code'
));
$data = curl_exec($ch);
var_dump($data);
exit;
And in response, I am successfully able to get the access_token
.作为回应,我成功地获得了
access_token
。
Now I am trying to go directly to this page in browser https://www.googleapis.com/androidpublisher/v3/applications/com.rosterelf.android.phone/reviews?access_token=ACCESS-TOKEN but it keeps saying me... Now I am trying to go directly to this page in browser https://www.googleapis.com/androidpublisher/v3/applications/com.rosterelf.android.phone/reviews?access_token=ACCESS-TOKEN but it keeps saying me.. .
Request had invalid authentication credentials.
请求具有无效的身份验证凭据。 Expected OAuth 2 access token, login cookie or other valid authentication credential.
预期 OAuth 2 访问令牌、登录 cookie 或其他有效的身份验证凭据。 See https://developers.google.com/identity/sign-in/web/devconsole-project
请参阅https://developers.google.com/identity/sign-in/web/devconsole-project
-> I have checked the roles and permissions and it has owner
as a permission in service account. -> 我已经检查了角色和权限,并且它在服务帐户中拥有
owner
作为权限。
-> My REDIRECT-URI
also the same URL throughout this process. -> 在整个过程中,我的
REDIRECT-URI
也是相同的 URL。
I event tried this URL to fetch the reviews https://androidpublisher.googleapis.com/androidpublisher/v3/applications/com.rosterelf.android.phone/reviews/review?access_token=ACCESS-TOKEN but having the same error. I event tried this URL to fetch the reviews https://androidpublisher.googleapis.com/androidpublisher/v3/applications/com.rosterelf.android.phone/reviews/review?access_token=ACCESS-TOKEN but having the same error.
Can someone please guide me what am I missing from here and why I am getting here and what exactly I should do from here on to get the reviews?有人可以指导我从这里缺少什么,为什么我会来到这里,从这里开始我应该做什么来获得评论?
Any help or suggestions will be highly appreciated.任何帮助或建议将不胜感激。
Thanks in advance.提前致谢。
This is an example for that API using the official client library.这是使用官方客户端库的 API 的示例。 I believe this code is for service account authentication.
我相信此代码用于服务帐户身份验证。 The service account will need to be properly configured see using_a_service_account How to create service account credetinals just remember to enable the proper library.
需要正确配置服务帐户,请参阅using_a_service_account如何创建服务帐户凭据只需记住启用正确的库。
<?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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.