访问youtube api数据时出错404

时间:2015-01-07 15:42:44

标签: java oauth-2.0 youtube-api

我开发了一个独立的程序来根据一个assest id找到一个视频ID。为此,我使用服务帐户身份验证来生成访问令牌。当我在我的url中传递访问令牌时,显示404未找到异常。有人遇到过这样的问题吗?

代码:

String EmailId = "xxxxxx@developer.gserviceaccount.com";

            //passing Scope
            @SuppressWarnings({ "unchecked", "rawtypes" })
              List<String>scops = new <String>ArrayList();
              scops.add("https://www.googleapis.com/auth/youtubepartner");

            final HttpTransport TRANSPORT = new NetHttpTransport();
            final JsonFactory JSON_FACTORY = new JacksonFactory();

         // Create a listener for automatic refresh OAuthAccessToken
            List<CredentialRefreshListener> list = new ArrayList<CredentialRefreshListener>();
            list.add(new CredentialRefreshListener() {
                @Override
                public void onTokenResponse(Credential credential,
                        TokenResponse tokenResponse) throws IOException {
                    System.out.println(tokenResponse.toPrettyString());

                }

                public void onTokenErrorResponse(Credential credential,
                        TokenErrorResponse tokenErrorResponse)
                        throws IOException {
                    System.err.println("Error: "
                            + tokenErrorResponse.toPrettyString());
                }


            });
            GoogleCredential credential = new GoogleCredential.Builder()
            .setTransport(TRANSPORT)
            .setJsonFactory(JSON_FACTORY)
            .setServiceAccountId(EmailId)
            .setServiceAccountScopes(scops)
            .setServiceAccountPrivateKeyFromP12File(new File("xxxxxx.p12"))
            .setRefreshListeners(list)
            .build();
            /*YouTube youtube = new YouTube.Builder(TRANSPORT,
                    JSON_FACTORY, credential).setApplicationName("test1-bd3f7f252932").build();*/
            credential.refreshToken();

我收到了“令牌”,现在我将access_token作为参数传递到我的实际youtube网址中,以获取视频ID:https://www.googleapis.com/youtube/partner/v1/assetSearch?metadataSearchFields=customId%3Axxxxx&access_token=ya29.9AD4t0HKE-ByFyeXhz7bO6Ha1Ej4ybzrMk2jjlUsvQdRAK-D6wrRr50Sn9KZ01YunTaPRDHpT4JEgQ

在运行时我得到了例外:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "Not Found"
   }
  ],
  "code": 404,
  "message": "Not Found"
 }
}

提前致谢!

0 个答案:

没有答案