Не могу вставить видео YouTube, используя java - PullRequest
0 голосов
/ 27 февраля 2020

Пожалуйста, объясните подробную ошибку с кодом ниже: Authen + путь файла в порядке, пожалуйста, поддержите.

public class ApiExample {    
    private static final String CLIENT_SECRETS = "client_secret.json";    
    private static final Collection<String> SCOPES = Arrays.asList("https://www.googleapis.com/auth/youtube.upload");    
    private static final String APPLICATION_NAME = "API code samples";    
    private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();   
    public static Credential authorize(final NetHttpTransport httpTransport) throws IOException {    
        // Load client secrets.    
        InputStream in = ApiExample.class.getResourceAsStream(CLIENT_SECRETS);    
        GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));    
        // Build flow and trigger user authorization request.    
        GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(httpTransport, JSON_FACTORY, clientSecrets, SCOPES).build();    
        Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");    
        return credential;    
    }
    public static YouTube getService() throws GeneralSecurityException, IOException {    
        final NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();    
        Credential credential = authorize(httpTransport);    
        return new YouTube.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();    
    }    
    public static void main(String[] args) throws GeneralSecurityException, IOException, GoogleJsonResponseException {    
        YouTube youtubeService = getService();    
        // Define the Video object, which will be uploaded as the request body.    
        Video video = new Video();    
        VideoStatus status = new VideoStatus();    
        status.setPrivacyStatus("public");    
        status.setEmbeddable(true);    
        status.setLicense("youtube");    
        video.setStatus(status);    
        // Add the snippet object property to the Video object.    
        VideoSnippet snippet = new VideoSnippet();    
        snippet.setTitle("Chương 5");    
        // snippet.setChannelId("UCMINtZzALW83UuWpjC_H51Q");    
        snippet.setDescription("chương 5");    
        String[] tags = { "truyen ngon tinh", };    
        snippet.setTags(Arrays.asList(tags));    
        snippet.setCategoryId("1");    
        video.setSnippet(snippet);    
        // TODO: For this request to work, you must replace "YOUR_FILE"    
        // with a pointer to the actual file you are uploading.    
        // The maximum file size for this operation is 128GB.    
        String file = Constants.currentPath + Constants.mp4 + File.separator + "6" + File.separator + "6" + Constants.ext_video_mp4;    
        File mediaFile = new File(file);    
        InputStreamContent mediaContent = new InputStreamContent("video/*", new BufferedInputStream(new FileInputStream(mediaFile)));    
        mediaContent.setLength(mediaFile.length());    
        // Define and execute the API request    
        YouTube.Videos.Insert request = youtubeService.videos().insert("processingDetails", video, mediaContent);    
        Video response = request.setAutoLevels(false).setNotifySubscribers(true).setStabilize(false).execute();    
        System.out.println(response);    
    }    
}        

====================== Ошибка

"код": 400,

"ошибки": [{

"домен": "youtube.part",

"местоположение": "часть",

"locationType": " параметр ",

" сообщение ":" {0} ",

" причина ":" непредвиденный случай "

}],

" сообщение " : "{0}"

Спасибо,

1 Ответ

0 голосов
/ 03 марта 2020

Кажется, вы получаете ошибку типа 400, а это означает badRequest . Проверьте эту документацию на Youtube и попытайтесь ее решить.

enter image description here

для типов ошибок, пожалуйста, ознакомьтесь с этой документацией:

https://developers.google.com/youtube/v3/docs/core_errors

...