如https://developer.android.com/google/play/billing/billing_best_practices
所述,我尝试验证服务器上的移动用户购买情况我遇到了一个臭名昭著的错误:“用于调用Google Play开发者API的项目ID尚未在Google Play开发者控制台中链接。”
在大量研究SO,Google等之后,...仍然有问题,我寻求您的帮助。
这是我的设置:
代码:
compile 'com.google.http-client:google-http-client-gson:1.25.0'
compile 'com.google.apis:google-api-services-androidpublisher:v3-rev30-1.25.0'
val httpTransport = GoogleNetHttpTransport.newTrustedTransport()
val jsonFactory = GsonFactory.getDefaultInstance()
val applicationName = "MYAPP"
val packageName = "my.package"
val json = "copy/paste json key here"
val credential = GoogleCredential.fromStream(StringInputStream(json), httpTransport, jsonFactory)
.createScoped(listOf((AndroidPublisherScopes.ANDROIDPUBLISHER)))
val publisher = AndroidPublisher.Builder(httpTransport, jsonFactory, credential)
.setApplicationName(applicationName)
.build()
val productId = "product_id"
val userPurchaseToken = "a_token"
val get = publisher.purchases()
.products()
.get(packageName, productId, userPurchaseToken)
val purchase = get.execute()
Logger.getLogger("Payment user").info("Found google purchase item ${purchase.toPrettyString()}")
然后我得到了异常
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code": 403,
"errors": [
{
"domain": "androidpublisher",
"message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console.",
"reason": "projectNotLinked"
}
],
"message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:150)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1067)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
请注意,我已经等待了24小时,但仍然遇到相同的错误。
我在这里完全迷路了...
为什么我的密钥可用于列出APK,但无法验证购买?
编辑:添加了第5步
答案 0 :(得分:0)
对我来说,这部分有所帮助。
If you get the same error again, maybe is because you have configured and
purchased products in your console before linking the project.
To solve it, simply add new product in your app.