亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 Golang 中正確使用 OAuth2 獲取谷歌電子郵件

如何在 Golang 中正確使用 OAuth2 獲取谷歌電子郵件

Go
翻閱古今 2021-09-27 21:02:54
我已經嘗試通過golang.com/x/oauth2庫成功使用 OAuth 進行身份驗證。// provider variable is oauth2.Config// scope is: https://www.googleapis.com/auth/userinfo.emailurl := provider.AuthCodeURL(``) // redirect URL從客戶端重定向回來后,我auth_code成功發送auth_code := ctx.Request.URL.RawQuery // code=XXXXif len(auth_code) > 5 {    auth_code = auth_code[5:] // XXXX}tok, err := provider.Exchange(oauth2.NoContext, auth_code)if err == nil {    client := provider.Client(oauth2.NoContext, tok)    email_url := `https://www.googleapis.com/auth/userinfo.email`    //Log.Describe(client)    response, err := client.Get(email_url)     if err == nil {        ctx.Render(`login_oauth`, response)        //handled = true    }}//Log.Describe(err)我沒有發現任何可以告訴response(Body空的)電子郵件部分的內容:{    "Status": "200 OK",    "StatusCode": 200,    "Proto": "HTTP/1.1",    "ProtoMajor": 1,    "ProtoMinor": 1,    "Header": {        "Alternate-Protocol": [            "443:quic,p=0.5"        ],        "Cache-Control": [            "private, max-age=0"        ],        "Content-Type": [            "text/plain"        ],        "Date": [            "Tue, 14 Apr 2015 05:52:17 GMT"        ],        "Expires": [            "Tue, 14 Apr 2015 05:52:17 GMT"        ],        "Server": [            "GSE"        ],        "X-Content-Type-Options": [            "nosniff"        ],        "X-Frame-Options": [            "SAMEORIGIN"        ],        "X-Xss-Protection": [            "1; mode=block"        ]    },    "Body": {}, // empty!!!    "ContentLength": -1,    "TransferEncoding": [        "chunked"    ],    "Close": false,    "Trailer": null,    "Request": {        "Method": "GET",        "URL": {            "Scheme": "https",            "Opaque": "",            "User": null,            "Host": "www.googleapis.com",            "Path": "/auth/userinfo.email",            "RawQuery": "",            "Fragment": ""        }, 第一個問題,如何正確獲取郵箱?不使用 Google+ API。
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 210 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號