Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. @Path("/gdrive")
  2. public class GDrive {
  3.  
  4. private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
  5. private static final List<String> SCOPES = Arrays.asList(DriveScopes.DRIVE_READONLY);
  6.  
  7. @GET
  8. @Path("/start")
  9. public void start(@Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException {
  10.  
  11. InputStream in = GDrive.class.getResourceAsStream("/client_secret.json");
  12. GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
  13.  
  14. GoogleAuthorizationCodeRequestUrl flow = new GoogleAuthorizationCodeRequestUrl( clientSecrets,
  15. "http://localhost:8080/GDriveRest/app/gdrive/finish",
  16. SCOPES);
  17. flow.put("access-type", "offline");
  18. flow.put("include_granted_scopes", "true");
  19.  
  20. response.sendRedirect(flow.toString());
  21. }
  22.  
  23. @GET
  24. @Path("/finish")
  25. public void finish(@Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException {
  26.  
  27. if (request.getParameter("code") != null) {
  28. response.sendRedirect("http://m.memegen.com/1yx6o5.jpg?"+request.getParameter("code"));
  29. }
  30. else {
  31. response.sendRedirect("https://img.memecdn.com/wat-error_c_1405685.jpg");
  32. }
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement