在服务帐户中传递新URL时无效的范围错误

时间:2014-12-19 15:32:46

标签: java youtube youtube-api

我做了一些代码来使用谷歌服务帐户点击Youtube网址。我通过范围的是获得5个记录列表。但现在我改变了它显示的范围" invalid_scope"

错误是:

" ERROR_DESCRIPTION" :" https://www.googleapis.com/youtube/v3/videos无效范围。"

here my code is:

//Passing ServiceAccount details
            String EmailId = "test@developer.gserviceaccount.com";
            @SuppressWarnings({ "unchecked", "rawtypes" })
            List<String>scops = new <String>ArrayList();
              //scops.add("https://www.googleapis.com/auth/youtubepartner");
              scops.add("https://www.googleapis.com/youtube/v3/videos");
            //scops.add("https://www.googleapis.com/youtube/partner");

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

            GoogleCredential credential = new GoogleCredential.Builder()
            .setTransport(TRANSPORT)
            .setJsonFactory(JSON_FACTORY)
            .setServiceAccountId(EmailId)
            .setServiceAccountScopes(scops)
            .setServiceAccountPrivateKeyFromP12File(new File("test.p12"))
            .build();
            System.out.println("credential............."+credential);
            YouTube youtube=new YouTube.Builder(TRANSPORT, JSON_FACTORY, credential).setApplicationName("test").build();

            // Define the API request for retrieving search results.
            YouTube.Search.List search = youtube.search().list("id");
            System.out.println("Search list............."+search);
            SearchListResponse searchResponse = search.execute();
            System.out.println("SearchResponce.........."+searchResponse);

Here i dont knw wt i did wrong,please any one help me to resolve this issue..its accepting "https://www.googleapis.com/auth/youtubepartner" this url only.

1 个答案:

答案 0 :(得分:0)

YouTube数据API不支持服务帐户。如果您需要进行写入(包括上传),或者只是获取API密钥并使用Google API客户端(https://developers.google.com/youtube/v3/code_samples/java)来读取数据(在API密钥之外无需身份验证),您必须使用oAuth )。