查询购买产品信息返回无效值使用Google Play Developer API

时间:2016-08-15 11:58:32

标签: google-play

这个问题可能类似here,但有些不同

1,我通过this

获取client_id client_secret

2,我通过以下方式获得authorization_code: https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri={REDIRECT_URIS}&client_id={CLIENT_ID}

3,通过以下方式获取refresh_token:

urls := "https://www.googleapis.com/oauth2/v4/token"

postData := "redirect_uri=%s&grant_type=authorization_code&client_id=%s&client_secret=%s&code=%s"
postData = fmt.Sprintf(postData, url.QueryEscape(REDIRECT_URL), url.QueryEscape(CLIENT_ID), url.QueryEscape(CLIENT_SECRET), url.QueryEscape(CODE))
beego.Debug("postData:", postData)

body, err := service.Post(urls, "application/x-www-form-urlencoded", bytes.NewReader([]byte(postData)))

4,我通过以下方式获取access_token:

urls := "https://www.googleapis.com/oauth2/v4/token"

postData := "grant_type=refresh_token&client_id=%s&client_secret=%s&refresh_token=%s"
postData = fmt.Sprintf(postData, url.QueryEscape(CLIENT_ID), url.QueryEscape(CLIENT_SECRET), url.QueryEscape(REFRESH_TOKEN))
beego.Debug("postData:", postData)

body, err := service.Post(urls, "application/x-www-form-urlencoded", bytes.NewReader([]byte(postData)))

我希望得到产品信息:

urls := "https://www.googleapis.com/androidpublisher/v2/applications/%s/purchases/products/%s/tokens/%s"
urls = fmt.Sprintf(urls, url.QueryEscape("cn.wps.moffice_premium"), url.QueryEscape("premium_sub_m"), url.QueryEscape("fngalnikxxxxxxcncnbfa.AO-J1OxEoo9RnI-tFqxxxxxxB6u-xbsnp74QYZQYsw_yDyLxxxxxxxaAohBFeafRTZBIioiljUt_ZVbexxxxxxPV7jD_QPQTpmftxpoQGzGloApv9mJnxBe5thDxxxxxxxLhpRRRWlK"))
header := http.Header{}
header.Add("Authorization", "Bearer "+accessToken)
body, err := service.Get(urls, header)

我得错了:

 {
 "error": {
 "errors": [
  {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid Value"
   }
  ],
  "code": 400,
  "message": "Invalid Value"
 }
}

我尝试这个url可以返回有效值:

"https://www.googleapis.com/androidpublisher/v2/applications/%s/purchases/subscriptions/%s/tokens/%s"

不确定还有什么可以尝试。 感谢您的帮助和回复

1 个答案:

答案 0 :(得分:4)

我找到原因。我的订单商品类型为" subs",因此无法使用此Purchases.products 我使用订单商品类型" inapp",使用Purchases.products返回200。