2015-05-29 68 views
-1

我'嘗試與谷歌打交道的OAuth2試圖從谷歌請求訪問令牌的oauth2

我的應用程序VILL被所謂的服務器應用程序開始。它應該在沒有用戶輸入的情況下工作。到目前爲止我的代碼(僅試圖獲得訪問令牌):

Dim strToken = Request.QueryString("code") 

     Dim strExchange = "response_type=code" 
     strExchange += "&redirect_uri=http://xxxx.zzzzz.com/test/google.aspx" 
     strExchange += "&client_id=xxxx7hju.apps.googleusercontent.com" 
     strExchange += "&scope=&" 
     strExchange += "client_secret=yJpGI1yQBCvvxxxxx&grant_type=authorization_code" 
     Dim url = "https://accounts.google.com/o/oauth2/auth?" 
     Dim webClient As New System.Net.WebClient 
     Dim result As String = webClient.DownloadString(url & strExchange) 

     Response.Write(result) 

這讓我壞reguest(400)

回答

0

你可以試試這個Article負責處理谷歌的壓延機條目。他們可以爲oauth2.0認證技術獲得適當的文檔。希望所有的價值取自App.Config

clientId = ConfigurationManager.AppSettings("client_id").ToString 
clientSecret = ConfigurationManager.AppSettings("client_secret").ToString 
redirecturi = ConfigurationManager.AppSettings("redirect").ToString 
mainUser = ConfigurationManager.AppSettings("mainuser").ToString 
Public Sub authorize() 
     Dim Uri As String = "https://accounts.google.com/o/oauth2/auth?access_type=offline&response_type=code&client_id=" & clientId & "&redirect_uri=" & redirecturi & "&scope=https://www.googleapis.com/auth/calendar&login_hint=" & mainUser & "&include_granted_scopes=true" 
     Response.Redirect(Uri) 
End Sub 
+0

什麼是主要用戶? – Timo77

+0

主要用戶驗證用戶的郵件ID – 2015-05-29 15:51:15

+0

請求中的重定向URI:http://xx.xxxx.xom/xx/google.aspx與註冊的重定向URI不匹配。我懂了。在API控制檯上有一些地方我應該添加網址嗎? – Timo77

相關問題