Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Path("/gdrive")
- public class GDrive {
- private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
- private static final List<String> SCOPES = Arrays.asList(DriveScopes.DRIVE_READONLY);
- @GET
- @Path("/start")
- public void start(@Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException {
- InputStream in = GDrive.class.getResourceAsStream("/client_secret.json");
- GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
- GoogleAuthorizationCodeRequestUrl flow = new GoogleAuthorizationCodeRequestUrl( clientSecrets,
- "http://localhost:8080/GDriveRest/app/gdrive/finish",
- SCOPES);
- flow.put("access-type", "offline");
- flow.put("include_granted_scopes", "true");
- response.sendRedirect(flow.toString());
- }
- @GET
- @Path("/finish")
- public void finish(@Context HttpServletRequest request, @Context HttpServletResponse response) throws IOException {
- if (request.getParameter("code") != null) {
- response.sendRedirect("http://m.memegen.com/1yx6o5.jpg?"+request.getParameter("code"));
- }
- else {
- response.sendRedirect("https://img.memecdn.com/wat-error_c_1405685.jpg");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement