Здравствуйте.
Хочу написать простенькую программку что бы делать операции чтения-записи с Task.
Нашел простенький пример:
Код:
package com.main;
import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse;
import com.google.api.client.googleapis.auth.clientlogin.ClientLogin;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessTokenRequest.GoogleAuthorizationCodeGrant;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAuthorizationRequestUrl;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.tasks.v1.Tasks;
import com.google.api.services.tasks.v1.model.Task;
import com.google.api.services.tasks.v1.model.TaskList;
import com.google.api.services.tasks.v1.model.TaskLists;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Run {
static Tasks service;
public static void setUp() throws IOException {
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
// The clientId and clientSecret are copied from the API Access tab on
// the Google APIs Console
String clientId = "";
String clientSecret = "";
// Or your redirect URL for web based applications.
String redirectUrl = "";
String scope = "https://www.googleapis.com/auth/tasks";
// Step 1: Authorize -->
String authorizationUrl = new GoogleAuthorizationRequestUrl(clientId, redirectUrl, scope)
.build();
// Point or redirect your user to the authorizationUrl.
System.out.println("Go to the following link in your browser:");
System.out.println(authorizationUrl);
// Read the authorization code from the standard input stream.
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("What is the authorization code?");
String code = in.readLine();
// End of Step 1 <--
// Step 2: Exchange -->
AccessTokenResponse response = new GoogleAuthorizationCodeGrant(httpTransport, jsonFactory,
clientId, clientSecret, code, redirectUrl).execute();
// End of Step 2 <--
GoogleAccessProtectedResource accessProtectedResource = new GoogleAccessProtectedResource(
response.accessToken, httpTransport, jsonFactory, clientId, clientSecret,
response.refreshToken);
service = new Tasks(httpTransport, accessProtectedResource, jsonFactory);
service.setApplicationName("EasyTaskListTracker");
}
public static void main(String args[]){
try {
setUp();
} catch (IOException e) {
e.printStackTrace();
}
com.google.api.services.tasks.v1.model.Tasks tasks = null;
try {
tasks = service.tasks.list("@default").execute();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (Task task : tasks.items) {
System.out.println(task.title);
}
}
}
Как-то можно сделать так чтобы не приходилось каждый раз заходить в гугл и давать своё согласие на доступ к таскам?
То есть избежать этого
Код:
// Point or redirect your user to the authorizationUrl.
System.out.println("Go to the following link in your browser:");
System.out.println(authorizationUrl);
// Read the authorization code from the standard input stream.
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("What is the authorization code?");
String code = in.readLine();
// End of Step 1 <--