Google Play API返回" 400错误请求"

时间:2017-02-14 06:39:15

标签: api validation google-play product

以下是我的代码:

public class MyTestCase {

private static final Log log = LogFactory.getLog(ListApks.class);

public static void main(String[] args) {
    try {
        Preconditions.checkArgument(!Strings.isNullOrEmpty(ApplicationConfig.PACKAGE_NAME),
                "ApplicationConfig.PACKAGE_NAME cannot be null or empty!");

        // Create the API service.
        final AndroidPublisher service = AndroidPublisherHelper.init(
                ApplicationConfig.APPLICATION_NAME, ApplicationConfig.SERVICE_ACCOUNT_EMAIL);
        final AndroidPublisher.Edits edits = service.edits();

        // Create a new edit to make changes.
        AndroidPublisher.Edits.Insert editRequest = edits
                .insert(ApplicationConfig.PACKAGE_NAME,
                        null /** no content */);
        AppEdit appEdit = editRequest.execute();


        Get purchases = service.purchases().products().get(ApplicationConfig.PACKAGE_NAME, "consumer", "bg46378");
        System.out.println(purchases);
        ProductPurchase purchase = purchases.execute();

    } catch (IOException | GeneralSecurityException ex) {
        log.error("Exception was thrown while updating listing", ex);
    }
}
}

问题是我不断得到:

SEVERE: Exception was thrown while updating listing
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
 {
   "code" : 400,
   "errors" : [ {
   "domain" : "global",
   "message" : "Invalid Value",
   "reason" : "invalid"
 } ],
 "message" : "Invalid Value"
 }

我不太确定这是否与令牌参数有关(我将在稍后用于有效载荷)。

编辑:我意识到我需要将purchaseToken放入GET的token参数中。 purchaseToken来自移动客户端上的有效负载。然而,我仍然得到相同的结果。我输入的purchaseToken看起来像

 String pt = "amopiilkhbjihjkfpbobeimo.AO-J1OzmDyihgfHLIPzDWfacU6EVf3rCj7LCbfypeO066DXddCoMgX7UeHesl32HA4K_x6rkYDEMR1e4rfhCYEMcc_8Xx_eySLIZ6BejrH8eJyZ0IhVREa0";

1 个答案:

答案 0 :(得分:0)

解决了我自己的问题。只需要进行复制和粘贴,而不是试图通过视力进行复制。通过将购买令牌从客户端应用程序复制到服务器应用程序来管理它。