嗨我在訪問Google Drive SDK時遇到了一些問題,主要是驗證步驟。從C#Web應用程序訪問Google Drive文件
我的.Net Web應用程序中有兩個主頁 - Default.aspx.cs
和WebForm1.aspx.cs
。 在Default.aspx
我有一個hyperlink
控制,是以用戶爲Google authentication page
當他們點擊鏈接:
https://accounts.google.com/o/oauth2/auth?response_type=code&scope=https://www.googleapis.com/auth/drive.file+https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile&redirect_uri=http://localhost/GoogleDriveTest/GoogleDriveTest/GoogleDriveTest/WebForm1.aspx&state=/profile&client_id=*CLIENT_ID*&approval_prompt=force
一旦用戶被重定向到REDIRECT_URI
(WebForm1
),我使用這段代碼訪問authorization
代碼:
HttpRequestInfo request = new HttpRequestInfo(Request);
code = Request.QueryString["code"];
現在我被卡住了。我知道我需要現在POST
此代碼:
https://accounts.google.com/o/oauth2/token <insert POST parameters here>
但我完全被卡住至於如何做到這一點。我已經嘗試了很多東西,但我得到的全部:
Server time out error - it failed to connect to the requested server
如何解決此問題?
編輯24/09/2012:
與Visual Studio 2012的新版本,他們已經將OAuth的所以它需要認證的護理: http://www.asp.net/vnext/overview/videos/oauth-in-the-default-aspnet-45-templates
這意味着用戶可以登錄通過Google等外部帳戶登錄本地網絡應用程序。
這是否意味着,一旦用戶通過Google登錄,我就可以獲取我需要的Google Drive文件?或者這只是爲了在本地Web應用程序中更輕鬆地進行註冊處理?
再次感謝。
這是我的錯誤:
[SocketException (0x274c): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond [2404:6800:4008:c01::54]:443]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +251
System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +279
[WebException: Unable to connect to the remote server]
System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) +6098637
System.Net.HttpWebRequest.GetRequestStream() +13
GoogleDriveTest.WebForm1.Page_Load(Object sender, EventArgs e) in C:\Projects\GoogleDriveTest\GoogleDriveTest\GoogleDriveTest\WebForm1.aspx.cs:101
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
解決!
我的問題是,在我的工作場所有一個代理,不允許任何連接到所需的URL。因此,我關閉了瀏覽器中的代理服務器,並繞過了它直接成功獲取訪問令牌所需的URL:D
@Shaks感謝編輯是新來這個:) – apet083
沒有任何問題的文檔。 :) –