我正在尝试使用ASPSnippets.GoogleAP.dll
和Google.Apis.Drive.v3.dll
从Google Drive下载文件。但面临一些挑战。正在下载文件,但它存在一些奇怪的HTML内容。如何从c#中的谷歌驱动器下载文件?
我使用下面的代码下载:
GoogleConnect.ClientId = "xxxx.apps.googleusercontent.com";
GoogleConnect.ClientSecret = "xxxxxx";
GoogleConnect.RedirectUri = Request.Url.AbsoluteUri.Split('?')[0];
GoogleConnect.API = EnumAPI.Drive;
if (!string.IsNullOrEmpty(Request.QueryString["code"]))
{
string code = Request.QueryString["code"];
string json = GoogleConnect.Fetch("me", code);
GoogleDriveFiles files = new JavaScriptSerializer().Deserialize<GoogleDriveFiles>(json);
//Remove the deleted files.
var driveService = new DriveService();
Label1.Text = theHiddenField1.Value;
WebClient wb = new WebClient();
wb.DownloadFile(theHiddenField1.Value, "C://" + fileName);
}
else if (Request.QueryString["error"] == "access_denied")
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Access denied.')", true);
}
else
{
GoogleConnect.Authorize("https://www.googleapis.com/auth/drive.readonly");
}
有人可以帮我解决这个问题?
你可以发布你收到的错误消息吗?或者你没有收到错误,它只是不下载? – Jay266
@ Jay266我没有收到任何错误msg文件正在下载soem html内容。 –
那么html说什么? –