嗨我在访问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
没有任何问题的文档。 :) –