Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 上传文件到谷歌硬盘_C#_Asp.net_Upload_Google Drive Api - Fatal编程技术网

C# 上传文件到谷歌硬盘

C# 上传文件到谷歌硬盘,c#,asp.net,upload,google-drive-api,C#,Asp.net,Upload,Google Drive Api,我需要在我的谷歌硬盘(pdf、word、excel)上上传文件,如何在ASP.NET中使用C#实现?你能把所有的段落一步一步地解释给我听吗?如果有用,我将最后一个测试代码放在下面: using System; using System.Collections.Generic; using System.Linq; using System.Web.UI; using System.Web.UI.WebControls; using ASPSnippets.GoogleAPI; using Sys

我需要在我的谷歌硬盘(pdf、word、excel)上上传文件,如何在ASP.NET中使用C#实现?你能把所有的段落一步一步地解释给我听吗?如果有用,我将最后一个测试代码放在下面:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPSnippets.GoogleAPI;
using System.Runtime.Serialization;
using System.IO;
using System.Web.Script.Serialization;

...

    protected void Page_Load(object sender, EventArgs e)
    {
        GoogleConnect.ClientId = "my_client_id";
        GoogleConnect.ClientSecret = "my_client_secret";
        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.PostFile(code, (HttpPostedFile)Session["File"], Session["Description"].ToString());
            GoogleDriveFile file = (new JavaScriptSerializer()).Deserialize<GoogleDriveFile>(json);
            tblFileDetails.Visible = true;
            lblTitle.Text = file.Title;
            lblId.Text = file.Id;
            imgIcon.ImageUrl = file.IconLink;
            lblCreatedDate.Text = file.CreatedDate.ToString();
            lnkDownload.NavigateUrl = file.WebContentLink;
            if (!string.IsNullOrEmpty(file.ThumbnailLink))
            {
                rowThumbnail.Visible = true;
                imgThumbnail.ImageUrl = file.ThumbnailLink;
            }
        }
        if (Request.QueryString["error"] == "access_denied")
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Access denied.')", true);
        }
    }

    protected void UploadFile(object sender, EventArgs e)
    {
        Session["File"] = FileUpload1.PostedFile;
        Session["Description"] = txtDescription.Text;
        GoogleConnect.Authorize("https://www.googleapis.com/auth/drive.file");
    }
}


public class GoogleDriveFile
{
    public string Id { get; set; }
    public string Title { get; set; }
    public string OriginalFilename { get; set; }
    public string ThumbnailLink { get; set; }
    public string IconLink { get; set; }
    public string WebContentLink { get; set; }
    public DateTime CreatedDate { get; set; }
    public DateTime ModifiedDate { get; set; }
}

我插入了重定向页面,但它给了我相同的错误。

您在Google开发者控制台中添加的重定向uri必须与您发送的内容完全匹配,因此应该添加重定向uri。或者可能


提示:确保将visual studio设置为不添加随机端口号。

当您在OAuth站点注册时,一旦应用程序获得授权,您将告诉它要将用户重定向到哪个网页。错误消息显示
http://localhost:61360/Prova.aspx
不是您注册的。你在google apps注册的URL是什么?我没有插入任何重定向页面。。。我只创建了一个应用程序,并在程序中使用了id和密码。我应该把什么作为重定向url?也许我可以更好地解释:在“console.developers.google.com”中,在“credentials”中,在我创建的“ID client OAuth 2.0”中,我只放了name字段。在“共识产品屏幕”中,我只有我的电子邮件地址和产品名称。错误消息中的链接(“访问…更新授权重定向URL”)是您的朋友
scope=https://www.googleapis.com/auth/drive.file
redirect_uri=http://localhost:61360/Prova.aspx
response_type=code
client_id=831126948299-2bopcsp3aee3harncqp5dpkq77sii3he.apps.googleusercontent.com
approval_prompt=auto
access_type=offline