ÀбâÀü¿¡...
¿ì¼± ¼Ò½º¸¦ ¸ÕÀú ¿Ã¸³´Ï´Ù.
1.¾ÆÁ÷ µî·Ï ºÎºÐÀ» ó¸®ÇÏÁö ¾Ê¾Ò½À´Ï´Ù.
2.¼Ò½º´Â ¿ÀÁ÷ °¡Àå ÃÖ±ÙÀÇ ÇÑ°³ÀÇ ¸®½ºÆ®¸¸À» °¡Á®¿É´Ï´Ù.
3.¼Ò½º´Â "ÀÚ¹Ù"¸¦ ±âÁØÀ¸·Î ÀÛ¼ºÇÏ¿´½À´Ï´Ù.
4.¾Èµå·ÎÀ̵忡¼ »ç¿ëÇϽǶ§´Â ¹®¼¸¦ parsingÇÏ´Â °÷À» xmlpullparsingÀ» ÀÌ¿ëÇÏ¿©
°¡Á®¿À½Ã°í, µî·ÏÀº post¸¦ ÀÌ¿ëÇϽøéµÉµíÇϳ׿ä.
<¼Ò½º>
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import javax.net.ssl.HttpsURLConnection;
class test
{
static ArrayList<String> items;
static ArrayList<String> items2;
static String USER_ID;
static String USER_Pass;
static String APP_NAME;
static String getGSID;
static String Note;
static String ar=null;
public static void main(String[] args)
{
USER_ID = "¾ÆÀ̵ð";
USER_Pass = "ºñ¹ø";
APP_NAME = "¾ÛÀ̸§";
post();
if(ar!=null)
{
listgeting();
}
if(ar!=null &&getGSID !=null)
{
listadd();
}
}
//ÀÏÁ¤À» Ãß°¡Çϴ°̴ϴÙ.
//¿ª½Ã³ª ÀÏ¹Ý OutputÀ¸·Î´Â µ¥ÀÌÅ͸¦ ¸ø¾¹´Ï´Ù.
//XMLÇüÅ·Πº¸³»¾ßµÉµíÇÕ´Ï´Ù.
public static void listadd()
{
try {
//±× pk¼¾ÅÒ¿¡ ÀÖ´Â ³»¿ëÀ¸·Î´Â gssesionsID¸¦ °¡Á®¿Í¾ßµÈ´Ù°í ÇßÁö¸¸. Á¢¼ÓÇÏ¸é ±×³É ¹Þ¾ÆÁý´Ï´Ù.
//µû¶ó¼ µû·Î ³ÖÀ» ÇÊ¿ä°¡ ¾ø½À´Ï´Ù.
URL url = new URL("
http://www.google.com/calendar/feeds/"+USER_ID+"/private/full");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/atom+xml");
con.setRequestProperty("Authorization", "GoogleLogin auth="+ar);
InputStream put = con.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(put));
String decode;
while((decode =br.readLine())!=null)
{
System.out.println(decode);
}
br.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//¸®½ºÆ®¿¡¼ °¡Àå ÃÖ±ÙÀÇ ¸®½ºÆ®ÀÇ Á¦¸ñÀ» °¡Á®¿É´Ï´Ù.
public static void listgeting()
{
try {
//°¡Á®¿À´Â ¹®¼ÇüŸ¦ µÎ°¡Áö, XML°ú JsonÇüÅ·Π°¡Á®¿Ã¼öÀִµ¥
//JsonÀ» °¡Á®¿À½Ç¶§´Â OutputStreamWriter¸¦ ÀÌ¿ëÇؼ "?alt=json"ÇϽøéµË´Ï´Ù.
//XMLÀº ±×³É ÀÌ·¸°Ô µÎ¸é ±×³É ±âº»À¸·Î XML·Î °¡Á®¿É´Ï´Ù.
URL url = new URL("
http://www.google.com/calendar/feeds/"+USER_ID+"/private/full");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setDoOutput(true);
con.setRequestMethod("GET");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("Authorization", "GoogleLogin auth="+ar);
InputStream put = con.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(put));
String decodedString;
while((decodedString = in.readLine())!=null)
{
if(decodedString.contains("<title type='text'>"))
{
int start = decodedString.lastIndexOf("<title type='text'>");
int end =decodedString.lastIndexOf("</title>");
Note= decodedString.substring(start+19,end);
System.out.println(Note);
}
}
in.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//·Î±×ÀÎ ¹× ÀÎÁõÅ° ¹ß±Þ ±×¸®°í ¸®½ºÆ®¸¦ °¡Á®¿É´Ï´Ù.
public static void post()
{
items = new ArrayList<String>();
try {
//±¸±Û¿¡ ·Î±×ÀÎÀ» ÇÕ´Ï´Ù.
//ÀԷ¹ÞÀº ¾ÆÀ̵ð¿Í Æнº¿öµå ±×¸®°í ¾ÛÀ̸§À» °¡Áö°í ·Î±×ÀÎÀ» ÇÔ°ú µ¿½Ã¿¡ Ä̸°´õ·Î
//¼ºñ½º¸¦¹Þ°í, Ãß°¡·Î ÀÎÁõÅ°µµ ¹Þ¾Æ¿É´Ï´Ù. ÀÎÁõÅ°´Â À§ÀÇ ¸Þ¼Òµå¿¡¼ Ä̸°´õ ¼ºñ½º¸¦
//ÀÌ¿ëÇϴµ¥ ¹Ýµå½Ã ÇÊ¿äÇÕ´Ï´Ù.
OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());
out.write(
+"&Passwd="+USER_Pass
+"&source="+APP_NAME
+"&service="+"cl");
out.flush();
InputStream put = con.getInputStream();
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String decodedString;
while((decodedString = in.readLine())!=null)
{
//ÀÌÄ£±¸°¡ SID,LSID,Auth¸¦ ¹Þ¾Æ¿É´Ï´Ù. 2¹ø°°¡ AuthÀ̹ǷΠAuthÀ妽º¸¸ »Ì¾Æ¼
//»ç¿ëÇϵµ·Ï ÇÕ´Ï´Ù.
items.add(decodedString);
}
in.close();
ar = items.get(2).substring(5);
System.out.println(ar);
//±¸±Û Ä̸°´õ ¸®½ºÆ®¸¦ ÃëµæÇÕ´Ï´Ù.
//·Î±×ÀÎÀ» ÀÎÁõÅ°¸¦ ÀÌ¿ëÇؼ ÇÕ´Ï´Ù. µû¶ó¼ À§¿¡¼ ¹Ýµå½Ã Auth¸¦ ¹ÞÀ¸¼Å¾ßµË´Ï´Ù.
URL url2 = new URL("
http://www.google.com/calendar/feeds/default/allcalendars/full");
HttpURLConnection conn =(HttpURLConnection)url2.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Authorization", "GoogleLogin auth = "+ar);
InputStream inner = conn.getInputStream();
items2 = new ArrayList<String>();
BufferedReader inner2 = new BufferedReader(new InputStreamReader(inner));
String incodedSring;
while((incodedSring= inner2.readLine())!=null)
{
//¿©±â¼´Â xml¹®¼¸¦ ±×³É ½ºÆ®¸µÀ¸·Î ¹Þ¾Æ¼ ó¸®Çߴµ¥ ¾Èµå·ÎÀ̵忡¼´Â
//XMLPullParsingÀ¸·Î ó¸®ÇϽøéµË´Ï´Ù.
items2.add(incodedSring);
for(int i =0; i<items2.size(); i++)
{
System.out.println(items2.get(i));
}
}
inner2.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
System.out.println("1Auth faild or Address Not Redirections");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("2Auth faild or Address Not Redirections");
}
}
}
* ±ÛÀ» µî·ÏÇϽǶ§ ²À ÇÊ¿äÇÑ °æ¿ì°¡ ¾Æ´Ï¸é °³ÀÎÁ¤º¸¸¦ ³²±âÁö ¸¶¼¼¿ä ^^ (¿¬¶ôó,À̸ÞÀÏÁÖ¼Ò,Áֹεî·Ï¹øÈ£ µî)