Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @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();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement