Youtube Data V3 Insert video Unauthorized

37 Views Asked by At

I'm a junior developer that wants to get started with Google Cloud.

I just created a project on GCP.

  • I enabled Youtube data v3 api.
  • Created a key for my service account
  • Created a Youtube channel

I integrated the Service account JSON with my project based on the guide at https://developers.google.com/zero-touch/guides/customer/quickstart/java-service-account

I tried to insert a video from my local file system to Youtube and I get exceeded quota error and I wasn't able to successfully upload a simple video of less than 2mb before this happened because I kept trying.

Attached are screenshots and code snippets

enter image description here

My code snippets

      String localFilePath = "/home/ubuntu/video.mp4";
      FileContent videoContent = new FileContent("video/*", new File(localFilePath));


      final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
      YouTube youTube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, new HttpCredentialsAdapter(getServiceCredential()))
        .setApplicationName("Game")
        .build();
      YouTube.Videos.Insert videoInsert = youTube.videos()
        .insert(Collections.singletonList("snippet,statistics,status"), videoMetadata, videoContent);

  private InputStream getCredentialInputStream() throws IOException {
    InputStream in = YouTubeService.class.getResourceAsStream(CREDENTIAL_PATH);
    if (in == null) {
      throw new FileNotFoundException("Resource not found: ".concat(CREDENTIAL_PATH));
    }
    return in;
  }


  private GoogleCredentials getServiceCredential() throws IOException {
    GoogleCredentials credentials = ServiceAccountCredentials.fromStream(
        Objects.requireNonNull(getCredentialInputStream()))
      .createScoped(SCOPES);
    return credentials;
  }
1

There are 1 best solutions below

0
Dion V On

As a reference to your question, there is a requirement needed as per markus from a previous post that may help with your concern aside from the quota error. It may be that you haven't setup your Youtube account or haven't setup your Youtube channel to upload videos.