401 - 请求视频源时令牌无效



我不知所措。在发出 API 请求时,我总是com.google.gdata.client.GoogleService$SessionExpiredException: Token invalid Token invalid

我有以程:

  1. 关联用户帐户
  2. 使用凭据获取视频上传条目

我用于链接用户(获取应用程序的权限(的代码使用该JdoDataStoreFactory来保留用户令牌并在 API 调用之间刷新信息。

当我要求用户授权我的应用时,我使用了以下范围:

https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/youtube.readonly

使用GoogleAuthorizationCodeFlow我执行一个loadCredentials从我的应用程序中传入我在请求其身份验证令牌时使用的 userId。 然后,我将这些凭据提供给YouTubeServicegetFeed 方法,请求视频源的 URL:http://gdata.youtube.com/feeds/api/users/default/uploads

它看起来像这样:

service.setOAuth2Credentials(credentials)
videoFeed = service.getFeed(new URL(USER_FEED_PREFIX + DEFAULT_USER
        + UPLOADS_FEED_SUFFIX), VideoFeed.class)

执行后,我总是得到堆栈跟踪:

com.google.gdata.client.GoogleService$SessionExpireException: Token 无效令牌无效

令牌无效错误

401

在 com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:570( 在 com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560( 在 com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538( 在 com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536( at com.google.gdata.client.Service.getFeed(Service.java:1135( at com.google.gdata.client.Service.getFeed(Service.java:998( at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:645( at com.google.gdata.client.Service.getFeed(Service.java:1017(

我向服务发起请求的方式是通过 curl,我的命令如下所示:

curl http://localhost:8080/user/someUserId/content

使用Wireshark,我在请求中看到以下内容:

GET /feeds/api/users/default/uploads HTTP/1.1                                                                                   
Authorization: Bearer <the_auth_token_for_the_user>
User-Agent: MyApp YouTube-Java/1.0 GData-Java/null(gzip)
X-GData-Client: MyApp
Accept-Encoding: gzip
GData-Version: 2.0
Cache-Control: no-cache
Pragma: no-cache
Host: gdata.youtube.com
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive

我被卡住了。

好的,我想通了。 我试图查询用户上传的视频,显然要使应用程序执行此操作,它必须针对https://www.googleapis.com/auth/youtube范围进行授权,而不是我配置的范围

最新更新