1

I am using front end react js and backend spring boot. When i try to upload video to youtube through youtube data api there need to oauth access. That url shows in spring boot console. Non of the request coming to the front end till video upload success. How can i get that request to frontend and show that in browser as popup.

here is my code.(which is in spring boot controller)

    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 = YoutubeController.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();
    }


    @GetMapping
    public void upload() throws GeneralSecurityException, IOException, GoogleJsonResponseException {
        YouTube youtubeService = getService();
        
        Video video = new Video();

        // Add the snippet object property to the Video object.
        VideoSnippet snippet = new VideoSnippet();
        snippet.setTitle("test");
        snippet.setDescription("description for testing purpose");
        video.setSnippet(snippet);
        
        // Add the status object property to the Video object.
        VideoStatus status = new VideoStatus();
        status.setUploadStatus("uploaded");
        video.setStatus(status);

        Resource load = storageService.load("video 3.mp4", "01", "1hruc8cc0gshe");//this returns the video file as resource
        File myfile = load.getFile();
        InputStreamContent mediaContent = new InputStreamContent("application/octet-stream",
                new BufferedInputStream(new FileInputStream(myfile)));
        mediaContent.setLength(myfile.length());

        // Define and execute the API request
        YouTube.Videos.Insert request = youtubeService.videos().insert("snippet, status", video, mediaContent);
        Video response = request.execute();
    }
dilanka
  • 31
  • 5

0 Answers0