8

There are several sample codes for how to programmatically obtain oauth2 authorization. I copied the code and named my class UtubeUploadAll. My code follows:

  private Credential authorize(List<String> scopes) throws Exception {

  // Load client secrets.
  InputStream cs = UtubeUpload.class.getResourceAsStream(
        "/client_secret.json");

  GoogleClientSecrets clientSecrets = new GoogleClientSecrets();

The statement:

  InputStream cs = UtubeUpload.class.getResourceAsStream(
        "/client_secret.json");

always returns null, no matter where I put the client_secrets.json file. I've put it in directory src, src/main, src/main/java, src/main/res... every place I can think of. I must completely mis-understand something here but I know not what. Can somebody help me out?

BinCodinLong
  • 721
  • 1
  • 7
  • 21

1 Answers1

12

I was working with the Google Calendar API for Java and had the same problem. Then i found the Google Quickstart Guide which said, that the correct location was src/main/resources/client_secret.json, which worked for me.

X.X_Mass_Developer
  • 717
  • 1
  • 8
  • 23
  • 3
    Thanks, it really helped after I have precisely followed instructions in the section "Step 2: Prepare the project" of the provided link (i.e. not to simply write the client-id and client-secret into existing json file, as it is often proposed, but download it from google developer or google api console, and also put the file exactly into specially created "resources" folder, not into "res" folder). – Elia12345 Jul 21 '16 at 08:34
  • I'm glad I could help. Accepting my answer would be very much appreciated. – X.X_Mass_Developer Sep 01 '16 at 07:34