gpt4 book ai didi

android - 访问 Android Play API 以进行订阅

转载 作者:太空狗 更新时间:2023-10-29 14:25:05 25 4
gpt4 key购买 nike

我试图获取有关通过我们的 Android 应用程序购买的订阅的信息,但一直通过此链接获取此响应

https://www.googleapis.com/androidpublisher/v1/applications/[package]/subscriptions/[product id]/purchases/[subscription id]?access_token=[access token]

我已经在 API 控制台中激活了 API 并创建了一个 Web 应用程序客户端 ID

client id from api console

然后我允许并从此链接复制给定的“代码”参数

https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&approval_prompt=force&redirect_uri=http://localhost&client_id=[client id]

并通过 php 从我们的服务器获取刷新 token 和访问 token (并在此存储刷新 token 供以后使用)

获取刷新 token $url = "https://accounts.google.com/o/oauth2/token ";

$post_fields = array(
"grant_type" => "authorization_code",
"code" => urldecode($code),
"client_id" => $client_id,
"client_secret" => $client_secret,
"redirect_uri" => urldecode($redirect_uri));

获取访问 token

$url = "https://accounts.google.com/o/oauth2/token";

$post_fields = $fields = array(
"grant_type" => "refresh_token",
"client_id" => $client_id,
"client_secret" => $client_secret,
"refresh_token" => $refresh_token);
$content = get_content($url, $post_fields);

这两个调用都是作为 POST 请求完成的

function get_content($url, $post_fields) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}

我的问题是为什么我仍然收到 Google 的回复

{
"error": {
"errors": [
{
"domain": "androidpublisher",
"reason": "developerDoesNotOwnApplication",
"message": "This developer account does not own the application."
}
],
"code": 401,
"message": "This developer account does not own the application."
}

最佳答案

我们遇到了同样的问题。据我所知,当您从不拥有该应用程序(不是所有者)的帐户生成 refresh_token 时,会发生此问题。因此,您必须从所有者帐户执行此操作,它会起作用。

关于android - 访问 Android Play API 以进行订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13286321/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com