我已经设置了我的API密钥,我的客户ID和我的客户机密,但是当我运行示例代码时,它进入SearchListResponse searchResponse = search.execute();,然后抛出一个GoogleJsonResponseException并说There was a service error 400 : Bad Request

我还需要在示例代码中进行其他更改吗?

Here是示例代码的链接。

这是堆栈跟踪。

com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
  "code" : 400,
  "errors" : [ {
    "domain" : "usageLimits",
    "message" : "Bad Request",
    "reason" : "keyInvalid"
  } ],
  "message" : "Bad Request"
}
    at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
    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:1056)
    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)
    at com.google.api.services.samples.youtube.cmdline.data.Search.main(Search.java:112)
There was a service error: 400 : Bad Request

最佳答案

问题实际上只是我的API密钥末尾有一个空格,使密钥无效。

关于java - YouTube API(数据)试图运行示例代码进行搜索,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59459777/

10-10 08:46