Reputation: 658
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.
Upvotes: 2
Views: 1006
Reputation: 658
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)
Upvotes: 3