30
Google Data API 2012/2/22

Google Data API

  • Upload
    tomas

  • View
    84

  • Download
    0

Embed Size (px)

DESCRIPTION

Google Data API. 2012/2/22. Google Data API 存取架構. Google Service Gmail 、 Document 、 Account 、 Analytics 、 YouTuBe 、 Maps …. 服務 ( 全部都是雲 ). Google Data API. API. 認證. WEB. Windows. Mobile. 程式. Google Account :認證 Google Calendar :日曆 Google Chart :圖表 Google Document :文件 ( 線上問卷、通訊錄資料蒐集 ) - PowerPoint PPT Presentation

Citation preview

Page 1: Google Data API

Google Data API

2012/2/22

Page 2: Google Data API

Google ServiceGmail、 Document、 Account、 Analytics、

YouTuBe、Maps …

Google Data API

認證

WEB Windows Mobile

Google Data API 存取架構服務 ( 全部都是雲 )

API

程式

Page 3: Google Data API

• Google Account :認證• Google Calendar :日曆• Google Chart :圖表• Google Document :文件 ( 線上問卷、通訊錄資料蒐集 )

• Google Search :搜尋引擎• YouTuBe :影音• Gmail

• Google Maps :網路地圖

Page 4: Google Data API

申請 Google 帳號• Gmail 帳號 (rfidctu/rfidctu3600)

Page 5: Google Data API

還需要 Google_API_Library (I)• http://code.google.com/intl/zh-TW/apis/gdata/

用戶端程式

Google Data API

Page 6: Google Data API

還需要 Google_API_Library (II)

.NET

Page 7: Google Data API

還需要 Google_API_Library (III)

下載然後安裝

Page 8: Google Data API

Google_API_Library DEMO

• Sample Code

• DLL :寫程式需要• 各位需要做的就是整合變成一個可用的系統

C:\Documents and Settings\Administrator\My Documents\Google Data API SDK\Sources

Page 9: Google Data API

Google Single Sign on• 所有服務用單一登入窗口

Page 10: Google Data API

Goolge 認證 UI• 以 Google Document 為例

Page 11: Google Data API

如何透過程式使用 Goolge 認證?• Google Data API

• 呼叫任何一種服務前都需要通過認證• 沒有特別 ( 專門 ) 的 API

• 所以借用呼叫任何一種服務,只要可以被叫用,就表示通過認證

Page 12: Google Data API

Google Account 透過 WEB 使用方式

• Google Account 使用方式:最簡單的方法是使用ClientLogin 這個 API

• 可以使用瀏覽器先測試– https://www.google.com/accounts/ClientLogin?

accountType=HOSTED_OR_GOOGLE&[email protected]&Passwd=PASSWORD&service=xapi&source=YourCompany-YourApp-Version

[email protected] 是你的 Google 帳號, Passwd= 密碼。 service 是要使用的服務名稱,如果要使用 Google Calendar ,那就要寫 cl

– 注意上面的關鍵字是大小寫有別的

Page 13: Google Data API

ClientLogin 之結果

正確

錯誤

Page 14: Google Data API

借用 Gmail 的呼叫服務完成認證.NET Windows Form

• 新專案,命名為 Google_API

Button2Button1

TextBox1

TextBox2

Page 15: Google Data API

http://office.microsoft.com/zh-tw/images/

http://www.iconfinder.net/

Free icon & image

Page 16: Google Data API

Button2_Click ' 取消登入 Private Sub Button2_Click(ByVal sender As System.Object,

ByVal e As System.EventArgs) Handles Button2.Click ' 取回使用者回應的資訊 Dim r As Windows.Forms.DialogResult r = MessageBox.Show("確定要取消? ", "取消登入 ",

MessageBoxButtons.OKCancel) ' 使用者選擇 ok,確定要離開 If r = Windows.Forms.DialogResult.OK Then Application.Exit() End If End Sub

Page 17: Google Data API

Button1_Click ' 確認登入 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles

Button1.Click ' 檢查輸入不為空 If Trim(TextBox1.Text) = "" Or Trim(TextBox2.Text) = "" Then MessageBox.Show("請輸入完整的帳號與密碼! ") Exit Sub End If ' 開始 Google Account確認 Dim objClient As New System.Net.WebClient Dim response As String

' 宣告 Gppgle API呼叫變數 ' 透過服務認證 Try objClient.Credentials = New System.Net.NetworkCredential(TextBox1.Text, TextBox2.Text) response = System.Text.Encoding.UTF8.GetString(objClient.DownloadData("https://mail.google.com/

mail/feed/atom")) MessageBox.Show("認證成功 ") Catch ex As Exception MessageBox.Show("認證失敗 ") End Try End Sub 可以轉成 Web Form?

Page 18: Google Data API

重點在• https://mail.google.com/mail/feed/atom

– http://code.google.com/intl/zh-TW/apis/gmail/docs/inbox_feed.html

這裡幾乎都找的到

不同服務對應一個 API URI

Page 19: Google Data API

可改進問題• 編號: 1

• 問題:判斷目前系統是是可以連上線• 提示:在 Form_Load 事件中加入判斷目前是否可以上網,如果不行,則系統不再往下執行…

Page 20: Google Data API

Google Chart API

Page 21: Google Data API

API Format

• 呼叫方式– http://chart.apis.google.com/chart? 參數– https://chart.googleapis.com/chart? 參數

• 使用方式– <img src=“ 呼叫方式” >

Page 22: Google Data API

參數 (I)• chs :圖片大小, chs=500x200 • cht :圖片類型, cht=lxy…

– http://code.google.com/intl/zh-TW/apis/chart/image/docs/chart_params.html

• chd :圖片資料, chd=t:10,20,40,80,90,95,99|0,30,40,50,60,70,80|-1|0,0,0,10,22,35,85– t: 使用數字,第一組是資料所在 x 座標,每組中間

用 | 分開,每組數列間用 -1 分隔– http://code.google.com/intl/zh-TW/apis/chart/image/

docs/data_formats.html

Page 23: Google Data API

參數 (II)

• chco :顏色,每組間用 , 分隔• chdl: 圖片的 legend , chdl=Ponies|Unicorns

• chls :線的大小, chls=2,4,1|1– 寬 , 長 , 每個點的間隔,每組參數間用 | 分開

• chxr:xy 軸的 label , chxr=0,1,10,1|1,1,5,1– 配合 chxt

– y,y 最小 ,y 最大 , 間隔 |x,x 最小 ,x 最大 , 間隔• chxt: 圖片要出現的軸線標示, chxt=y,x

大小寫有差別

Page 24: Google Data API

• <img src="http://chart.apis.google.com/chart?chs=440x220&cht=lxy&chco=3072F3,FF0000&chd=t:10,20,40,80,90,95,99|0,30,40,50,60,70,80|-1|0,0,0,10,22,35,85&chdl=Ponies|Unicorns&chls=2,4,1|1&chxr=0,0,100,10|1,0,100,10&chxt=y,x">

Page 25: Google Data API

Practice• 3 組資料 姓名 國文 英文 數學

大雄 65 80 25

小叮噹 70 80 90

技安 20 50 80

變成

Page 26: Google Data API

Chart Wizard• http://code.google.com/intl/zh-TW/apis/

chart/image/docs/chart_wizard.html

Page 27: Google Data API

Practice Answerhttp://chart.apis.google.com/chart

?chxl=0:|國文 |英文 |數學    &chxr=0,0,95|1,0,100,20 &chxs=0,676767,15,0,l,676767|1,000000,12.5,0,lt,000000 &chxtc=1,3 &chxt=x,y &chbh=a &chs=600x400 &cht=bvg &chco=A2C180,3D7930,FF9900 &chd=t:65,80,25|70,80,90|20,50,80 &chdl=大雄 |小叮噹 |技安    &chtt=成績    &chts=FF0000,11.5

中文需要編碼

Page 28: Google Data API

Call by .NETWebBrowser1.Navigate(Application.StartupPath & "\aa.htm")

Page 29: Google Data API

Call by .NET

Button1

Page 30: Google Data API

Call by .NET Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As

System.EventArgs) Handles Button1.Click

Dim str1 As String = “xxxx” ‘xxx= 整個 api 字串前半段 Dim str3 As String = “vvvv” ‘vvv= 整個 api 字串後半段 Dim str2 As String

str2 = TextBox1.Text & "|" & TextBox2.Text & "|" & TextBox3.Text

‘ 寫入檔案 Dim FileNum As Integer

Dim strTemp As String

FileNum = FreeFile()

FileOpen(FileNum, Application.StartupPath & "\aa.htm", OpenMode.Output)

strTemp = str1 & str2 & str3

PrintLine(FileNum, strTemp)

FileClose(FileNum)

‘ 顯示圖檔 WebBrowser1.Navigate(Application.StartupPath & "\aa.htm")

End Sub