Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. @GET
  2. @Path("/start")
  3. public void start(@Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException {
  4.  
  5. String url = initFlow().newAuthorizationUrl().setRedirectUri("http://localhost:8080/GDriveRest/app/gdrive/finish").build();
  6. response.sendRedirect(url);
  7. }
  8.  
  9. @GET
  10. @Path("/finish")
  11. public void finish(@Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException {
  12.  
  13. AuthorizationCodeFlow flow = initFlow();
  14. flow.newTokenRequest(request.getParameter("code"));
  15.  
  16. response.sendRedirect("http://m.memegen.com/1yx6o5.jpg?"+request.getParameter("code")+"&id="+flow.getClientId());
  17. }
  18.  
  19. private AuthorizationCodeFlow initFlow() throws IOException {
  20.  
  21. InputStream in = GDrive.class.getResourceAsStream("/client_secret.json");
  22. GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
  23.  
  24. return new GoogleAuthorizationCodeFlow.Builder(new NetHttpTransport(),
  25. JacksonFactory.getDefaultInstance(),
  26. clientSecrets, SCOPES).setAccessType("offline").build();
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement