Google Cloud Platform Console:

首先先創建好專案,然後到「API和服務」底下「程式庫」

pic 2022-09-02 at 7.11.54 PM.png

搜尋「Google Calendar API」並且啟用他

也可以在這一步驟去增加不同的API,要在這裡啟用之後才能在後續設定 Scope

pic 2022-09-02 at 7.13.05 PM.png

接著再到「OAuth同意畫面」

User Type選取外部,接著填寫應用程式資訊(只填打*的)

pic 2022-09-02 at 7.13.57 PM.png

pic 2022-09-02 at 7.14.32 PM.png

pic 2022-09-02 at 7.15.25 PM.png

接著點選「新增或移除範圍」,搜尋Google Calendar API,這裡有許多Scope,可以取得不同的權限,這裡啟用第一個看到的Scope(…/auth/calendar)

pic 2022-09-02 at 7.16.01 PM.png

pic 2022-09-02 at 7.16.32 PM.png

pic 2022-09-02 at 7.17.24 PM.png

步驟3這裡是新增測試使用者,請新增要上傳日曆的那隻帳號。在還沒發佈應用程式之前,只有測試使用者能夠使用,別的帳號無法存取!

pic 2022-09-02 at 7.18.33 PM.png

完成之後,我們要申請Client ID跟Client Secret,來到「憑證」→「建立憑證」→「OAuth用戶端ID」

之後在應用程式類型選取「網頁應用程式」,已授權的重新導向URI填寫「http://127.0.0.1/ndhucourse/google/callback」(我的路徑是設在這裡)

這裡的redirect URI是能夠讓我們的server拿到回傳的code,再利用這個code來取得token。

pic 2022-09-02 at 7.19.04 PM.png

pic 2022-09-02 at 7.20.14 PM.png

好了之後,你就拿到專屬於你的Client ID跟Client Secret了!

pic 2022-09-02 at 7.20.35 PM.png