Ars*_*lan 5 php google-play in-app-subscription
我正在将 google play 应用内订阅集成到我的应用程序中。要访问 google API,首先我需要获取 access_token,然后在标头中使用它来访问订阅 API。按照程序(Android:inApp购买收据验证google play)我得到了我的凭据文件,如下所示
{
"type": "service_account",
"project_id": "my-project-id",
"private_key_id": "x",
"private_key": "-----BEGIN PRIVATE KEY-----y-----END PRIVATE KEY-----\n",
"client_email": "google-play-developer@z.iam.gserviceaccount.com",
"client_id": "x",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/google-play-developer%40y.iam.gserviceaccount.com"
}
Run Code Online (Sandbox Code Playgroud)
注意:真实的 id 和值替换为 x、y 和 z
接下来,为了用 JWT 交换 access_tokenm,我正在使用 php 的 Google API 客户端库 https://github.com/googleapis/google-api-php-client
这是我的代码
$client = new \Google_Client();
$client->setAuthConfig('client_secret.json');
$client->addScope('https://www.googleapis.com/auth/androidpublisher');
$client->setRedirectUri($request->redirect_uri);
$token = $client->fetchAccessTokenWithAuthCode($request->code);
Run Code Online (Sandbox Code Playgroud)
但我无法获取访问令牌。出现以下错误
{
"error": "invalid_request",
"error_description": "Could not determine client ID from request."
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1129 次 |
| 最近记录: |