3

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

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

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

来自 api 控制台的客户端 ID

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

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 从我们的服务器获取刷新令牌和访问令牌(并在此存储刷新令牌以供以后使用)

获取刷新令牌 $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));

获取访问令牌

$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."
 }

}

4

1 回答 1

1

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

于 2013-06-28T13:44:39.100 回答