访问Android Play API以进行订阅

时间:2012-11-08 09:40:02

标签: android api google-play in-app-subscription

我试图获取有关通过我们的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获取刷新令牌和访问令牌(并在此存储刷新令牌供以后使用)

获取刷新令牌     $ 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."
 }

}

1 个答案:

答案 0 :(得分:1)

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