我尝试使用 git hub 中提供的示例 java 代码在 java 中执行 YouTube 分析。示例代码允许我获得允许访问的用户同意页面,并尝试使用“reports()”执行查询。 query(" ").execute() 我收到 404 resource not found 响应。
执行以下方法时,我得到 404 not found 异常:
private static ResultTable executeViewsOverTimeQuery(YouTubeAnalytics analytics,
String id) throws IOException {
return analytics.reports()
.query("channel==" + id, // channel id
"2020-01-14", // Start date.
"2020-01-16", // End date.
"views,uniques") // Metrics.
.setDimensions("day")
.setSort("day")
.execute();
}
当我在 API Explorer 中尝试相同的操作时,它会返回 200 ok 响应。
API Explorer 网址: https ://apis-explorer.appspot.com/apis-explorer/#p/youtubeAnalytics/v2/youtubeAnalytics.reports.query
控制台日志:
2020 年 1 月 16 日晚上 7:12:08 com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
警告:无法更改所有人的权限:C:\Users\yoga.oauth-credentials
2020 年 1 月 16 日晚上 7:12:08 com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
警告:无法更改所有者的权限:C:\Users\yoga.oauth-credentials
2020-01-16 19:12:08.993:INFO::通过 org.mortbay.log.StdErrLog 记录到 STDERR
2020-01-16 19:12:08.994:INFO::jetty-6.1.26
2020-01-16 19:12:09.012:INFO::Started SocketConnector@localhost:8080
请在浏览器中打开以下地址: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com&redirect_uri=http://localhost:8080/ Callback&response_type=code&scope=https ://www.googleapis.com/auth/yt-analytics.readonly%20https://www.googleapis.com/auth/youtube.readonly
现在尝试在默认浏览器中打开该地址...
2020-01-16 19:12:21.400:INFO::Stopped SocketConnector@localhost:8080
默认频道:xxxxxxx@gmail.com (UCxxxxxxxxxxxxxxxxxxxxx)
IOException: 404 未找到
未找到
com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 未找到
未找到
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.analytics.YouTubeAnalyticsReports.executeViewsOverTimeQuery(YouTubeAnalyticsReports.java:134)
at com.google.api.services.samples.youtube.cmdline.analytics.YouTubeAnalyticsReports.main(YouTubeAnalyticsReports.java:103)