iT邦幫忙

2024 iThome 鐵人賽

DAY 30
0
生成式 AI

運用生成式 AI 服務 所提供的API 實做應用開發(以Gemini及ChatGPT為例)系列 第 30

7-5 驗證 OAuth & 回傳網址 實作串接 GMail 讀取及回覆 mail

  • 分享至 

  • xImage
  •  

7-5 驗證 OAuth & 回傳網址 實作 GPT 串接 GMail 讀取及 chatGPT 回覆 mail

https://ithelp.ithome.com.tw/upload/images/20240811/20046160F3hxRWsauh.png

比較嚴謹的 API 通常會用 OAuth 做驗證,例如 Google Workspace 裡的服務。

Gmail 也串上了 Gemini,可惜尙不支援中文(2024.7),所以GPT 串接 GMail 讀取信件內容,並回覆。

實作 讀寫 Gmail

步驟 1:設定 Oauth

  1. 前往 Google Cloud 控制台
  2. 創建一個新項目或選擇一個現有項目。
  3. 為您的項目啟用 Gmail API。 https://console.cloud.google.com/apis/library/gmail.googleapis.com

https://ithelp.ithome.com.tw/upload/images/20240801/200461605WG2pN6D11.png

  1. 創建 OAuth 2.0 憑證(客戶端 ID 和客戶端密鑰)。

https://ithelp.ithome.com.tw/upload/images/20240801/20046160RFAHUnlih0.png

https://ithelp.ithome.com.tw/upload/images/20240801/200461607IBK3pSWHo.png

https://ithelp.ithome.com.tw/upload/images/20240801/20046160HQfxa1g8Tz.png

  1. Authorized JavaScript origins 跟 Authorized redirect URIs 填 https://chat.openai.com

https://ithelp.ithome.com.tw/upload/images/20240801/20046160DGdwiLHhgd.pnghttps://ithelp.ithome.com.tw/upload/images/20240801/20046160nxJkaxfgRO.png

  1. 下載 JSON 獲得 key 值

https://ithelp.ithome.com.tw/upload/images/20240801/20046160ykOkBLXgnH.png

  1. 回到 ChatGPT 建立 GPT 選 配置 選 新增動作 選 驗證
  2. 從 JSON 中 找欄位 填入

https://ithelp.ithome.com.tw/upload/images/20240801/20046160ah4SEGnCIR.png

範圍 : https://www.googleapis.com/auth/gmail.readonly;https://www.googleapis.com/auth/gmail.send;https://www.googleapis.com/auth/gmail.modify;https://www.googleapis.com/auth/gmail.compose;https://www.googleapis.com/auth/gmail.labels

  1. 點 儲存之後回到配置 頁

https://ithelp.ithome.com.tw/upload/images/20240801/20046160FyDItaTweX.png

  1. 多了 回呼網址
  2. 複製到剛的 GCP Credential 頁

https://ithelp.ithome.com.tw/upload/images/20240801/20046160zrnaG3N1tn.png

  1. spec 不會寫,一樣給 ActionsGPT 寫:spec for gmail

https://ithelp.ithome.com.tw/upload/images/20240801/20046160NPJwYz1Mhg.png

  1. 貼回 GPT

  2. 沒加隱私權政策會錯誤,就請 ChatGPT 寫一個 貼到 Google Doc 再分享,就可以了

https://ithelp.ithome.com.tw/upload/images/20240801/20046160Wyx6ADIMWf.png

  1. 先 建立

https://ithelp.ithome.com.tw/upload/images/20240801/20046160JE1DjGD1uQ.png

  1. 測試 只能 在 建立好 GPT 後 測試,

https://ithelp.ithome.com.tw/upload/images/20240801/20046160aV8Hy4ngsk.png

  1. 完成後 會發現 當 call API 失敗時 , ChatGPT 很會加油添醋虛構郵件內容。

關於我

我是 Wolke。我是一名專業程式開發者,專長是開發 AI 和程式解決方案。

我投入了不少時間在專業發展上。我是多本書的作者,其中包括《LINE聊天機器人+AI+雲端+開源+程式:輕鬆入門到完整學習》《ChatGPT來襲,未來人人都需具備的運算思維!應用詠唱工程來釋放程式生產力—程式學習/開發篇》。也有出版線上課程,我熱衷於分享我的經驗和技術,幫助其他開發者更好地利用 AI 工具。

也在許多知名大學、論壇、社團擔任講者,如果貴方有需要也歡迎與我聯繫。
2023年 講座 紀錄

最後這篇文章若有切合你的需求,敬請訂閱按讚分享


上一篇
7-4 驗證 api key 以 LINE notify 服務 為例
下一篇
8-1 ChatGPT 的 API Playground 教學
系列文
運用生成式 AI 服務 所提供的API 實做應用開發(以Gemini及ChatGPT為例)36
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言