사용하기 전에 몇가지 제약이 존재하는듯.

1. google account 가 있어야 한다.
2. google calendar "모바일 설정"에서 자신의 phone number 인증을 받아야 한다.
3. 인증 받은 후 내 킬린더의 SMS 수신 여부를 설정해야 함.
4. gdata-src.java-1.40.0.zip 다운로드 받고.. lib 목록에 추가해야함.
5. 잘 사용해서 만들어 주면 땡.

sample
- 우선은 구글 계정 정보(id, pw)를 알아야 SMS를 전송할 수 있다.
- title에 입력된 데이터가 SMS로 전송된다.
- title이 길면 여러개로 쪼개져서 오기 때문에 받아보기 귀찮음. 알아서 사이즈를 맞춰야 할듯.

package google.sms;

import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.Date;

import com.google.gdata.client.calendar.CalendarService;
import com.google.gdata.data.DateTime;
import com.google.gdata.data.PlainTextConstruct;
import com.google.gdata.data.calendar.CalendarEntry;
import com.google.gdata.data.calendar.CalendarEventEntry;
import com.google.gdata.data.calendar.CalendarFeed;
import com.google.gdata.data.extensions.Reminder;
import com.google.gdata.data.extensions.When;
import com.google.gdata.data.extensions.Reminder.Method;
import com.google.gdata.util.ServiceException;

public class Launcher {

 String id = "id@gmail.com";
 String pw = "password";
 String calendarName = "SMS";
 
 public void test() throws IOException, ServiceException {
  CalendarService service = new CalendarService("sms notify");
 
  service.setUserCredentials(id, pw);

  String title = "문자 테스트 잘 받아보아라...11";
  String description = "테스트입니다.2";
 
  URL metafeedUrl = new URL("http://www.google.com/calendar/feeds/default/allcalendars/full");
  CalendarFeed resultFeed = service.getFeed(metafeedUrl, CalendarFeed.class);
  List entries = resultFeed.getEntries();
 
  for (int i = 0; i < entries.size(); i++) {
   CalendarEntry entry = (CalendarEntry)entries.get(i);
   String currCalendarName = entry.getTitle().getPlainText();
   System.out.println("\t" + currCalendarName);
 
   if (currCalendarName.equals(calendarName)) {
    sendDowntimeAlert(service, entry, title, description);
   }
  }
 
  System.out.println("\nTotal Entries: " + entries.size());

 }
 
 private void sendDowntimeAlert(CalendarService myService,
         CalendarEntry entry,
         String title,
         String description) throws IOException,
  ServiceException {
 
  String postUrlString = entry.getLink("alternate", "application/atom+xml").getHref();
 
  URL postUrl = new URL(postUrlString); //was: "http://www.google.com/calendar/feeds/jo@gmail.com/private/full"
 
  CalendarEventEntry myEntry = new CalendarEventEntry();
 
  myEntry.setTitle(new PlainTextConstruct(title));
  myEntry.setContent(new PlainTextConstruct(description));
 
  Date now = new Date();
 
  // 이거는 뭐.. 시간이 우떻게 되는 거임?? 도통..
  Long tzOffset = new Double(Double.parseDouble("9")).longValue() * 60 * 60 * 1000 + 1000 * 5;
 
  Date startDate = new Date(now.getTime());
  Date endDate = new Date(now.getTime());
  
 
  DateTime startTime  = new DateTime(startDate.getTime()  + tzOffset);
  DateTime endTime  = new DateTime(endDate.getTime()  + tzOffset);
 
  When eventTimes = new When();
  eventTimes.setStartTime(startTime);
  eventTimes.setEndTime(endTime);
  myEntry.addTime(eventTimes);
 
  // Send the request and receive the response:
  CalendarEventEntry insertedEntry = myService.insert(postUrl, myEntry);
  System.err.println("Got response for: "+insertedEntry.getTitle().getPlainText());
 
  for(When when : insertedEntry.getTimes()) {
   System.err.println("When: "+when.getStartTime()+" to "+when.getEndTime());
  }
 
  Reminder reminder = new Reminder();
  reminder.setMinutes(0);
  reminder.setMethod(Method.SMS);
  insertedEntry.getReminder().add(reminder);
  insertedEntry.update();
 }
 
 public static void main(String[] args) {
  try {
   new Launcher().test();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (ServiceException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
}

Posted by 짱가쟁이