2014-07-24 217 views
0

我不知道如何在日曆中插入事件。在我的網站上,您可以使用Google登錄,然後您可以在您的日曆中插入活動,但正如Google日曆API中所述,我需要發送我的ClientID和我的ClientSecret,並且我想使用您的ID。我不知道如何建立服務。Google日曆插入事件

public void setUp() throws IOException { 
HttpTransport httpTransport = new NetHttpTransport(); 
JacksonFactory jsonFactory = new JacksonFactory(); 

// The clientId and clientSecret can be found in Google Developers Console 
String clientId = "YOUR_CLIENT_ID"; 
String clientSecret = "YOUR_CLIENT_SECRET"; 

// Or your redirect URL for web based applications. 
String redirectUrl = "urn:ietf:wg:oauth:2.0:oob"; 
String scope = "https://www.googleapis.com/auth/calendar"; 

// 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); 

Calendar service = new Calendar(httpTransport, accessProtectedResource, jsonFactory); 
service.setApplicationName("YOUR_APPLICATION_NAME"); 

非常感謝!

回答