2

I am following the Google Drive's API with java (https://developers.google.com/drive/v2/web/quickstart/java), and there is this line of code where it reads a .json file in my project directory (I copied it there) that has client_id and client_secret in it.

    // Load client secrets.
    InputStream in = GoogleDrive.class.getResourceAsStream("client_id.json");
    this.clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

    // Build flow and trigger user authorization request.
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
            .setDataStoreFactory(DATA_STORE_FACTORY)
            .setAccessType("offline")
            .build();

I made a GoogleDrive.java class that makes logging in, uploading etc. easier.

How can I hard code the information in .json file and have google "load" it to clientsecrets, so that I can use this class in other applications as well. I am kind of a newbie in REST so a step by step note would be appreciated.

Thanks you all.

sorry_I_wont
  • 639
  • 1
  • 9
  • 16

1 Answers1

3

Found the answer, using this method(well, the same method, different signature) does the trick :)

public GoogleAuthorizationCodeFlow.Builder(HttpTransport transport,
                               JsonFactory jsonFactory,
                               String clientId,
                               String clientSecret,
                               Collection<String> scopes)
sorry_I_wont
  • 639
  • 1
  • 9
  • 16