I'm reading the google drive documentation but It's a bit unclear:
- I have to set the web-hook for each user on my application, or only once?
- There is any example of this configuration in java?
- How I can retrieve th changes for my users(maybe a cursor)?
Here is how I let users authenticate to my application:
@GET
@Path("/start")
public void start(@Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException {
String url = initFlow().newAuthorizationUrl().setRedirectUri("http://localhost:8080/GDriveRest/app/gdrive/finish").build();
response.sendRedirect(url);
}
@GET
@Path("/finish")
public void finish(@Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException {
AuthorizationCodeFlow flow = initFlow();
flow.newTokenRequest(request.getParameter("code"));
response.sendRedirect("http://m.memegen.com/1yx6o5.jpg?"+request.getParameter("code")+"&id="+flow.getClientId());
}
private AuthorizationCodeFlow initFlow() throws IOException {
InputStream in = GDrive.class.getResourceAsStream("/client_secret.json");
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
return new GoogleAuthorizationCodeFlow.Builder(new NetHttpTransport(),
JacksonFactory.getDefaultInstance(),
clientSecrets, SCOPES).setAccessType("offline").build();
}
How I can set webhooks?