Google drive api Gdrive无法下载且无法上载

Google drive api Gdrive无法下载且无法上载,google-drive-api,Google Drive Api,我正在使用GDRive insertFile和RevtrieveAllFiles上传和下载文件到googledrive。 我创建了一个客户端密码和Id,并修改了凭据。 该代码基于post in代码项目 但是它在Utilities.InsertFile中调试失败 在file.upload中,它失败,异常值不能为null-uriString。 在下载过程中,它在FileList files=request.Fetch()中失败带有 // First, create a reference to t

我正在使用GDRive insertFile和RevtrieveAllFiles上传和下载文件到googledrive。 我创建了一个客户端密码和Id,并修改了凭据。 该代码基于post in代码项目

但是它在Utilities.InsertFile中调试失败 在file.upload中,它失败,异常值不能为null-uriString。 在下载过程中,它在
FileList files=request.Fetch()中失败带有

 // First, create a reference to the service you wish to use.
    // For this app, it will be the Drive service. But it could be Tasks, Calendar, etc.
    // The CreateAuthenticator method is passed to the service which will use that when it is time to authenticate
    // the calls going to the service.
    _service = new DriveService(CreateAuthenticator());

    // Open a dialog box for the user to pick a file.
    OpenFileDialog dialog = new OpenFileDialog();
    dialog.AddExtension = true;
    dialog.DefaultExt = ".txt";
    dialog.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
    dialog.Multiselect = false;
    dialog.ShowDialog();


    File body = new File();
    body.Title = System.IO.Path.GetFileName(dialog.FileName);
    body.Description = "A test document";
    body.MimeType = "text/plain";

    System.IO.Stream fileStream = dialog.OpenFile();
    byte[] byteArray = new byte[fileStream.Length];
    fileStream.Read(byteArray, 0, (int)fileStream.Length);

    System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);

    // Get a listing of the existing files...
    List<File> fileList = Utilities.RetrieveAllFiles(_service);

    // Set a flag to keep track of whether the file already exists in the drive
    bool fileExists = false;

    foreach (File item in fileList)
    {
        if (item.Title == body.Title)
        {
            // File exists in the drive already!
            fileExists = true;
            MessageBoxResult result = System.Windows.MessageBox.Show("The file you picked already exists in your Google Drive. Do you wish to overwrite it?", "Confirmation", MessageBoxButton.YesNoCancel);
            if (result == MessageBoxResult.Yes)
            {

                // Yes... overwrite the file
                Utilities.UpdateFile(_service, item.Id, item.Title, item.Description, item.MimeType, dialog.FileName, true);
                List<File> allFiles = Utilities.RetrieveAllFiles(_service);

            }

            else if (result == MessageBoxResult.No)
            {

                // MessageBoxResult.No code here
              File f=             Utilities.insertFile(_service, System.IO.Path.GetFileName(dialog.FileName), "An uploaded document", "", "text/plain", dialog.FileName);
            }

            else
            {

                // MessageBoxResult.Cancel code here
                return;
            }
            break;
        }
    }

    // Check to see if the file existed. If not, it is a new file and must be uploaded.
    if (!fileExists)
    {
      File file=  Utilities.insertFile(_service, System.IO.Path.GetFileName(dialog.FileName), "An uploaded document", "", "text/plain", dialog.FileName);
      var list = Utilities.RetrieveAllFiles(_service);

    }

    System.Windows.MessageBox.Show("Upload Complete");
//首先,创建对要使用的服务的引用。
//对于此应用程序,它将是驱动器服务。但可能是任务、日历等。
//CreateAuthenticator方法被传递给服务,该服务将在进行身份验证时使用该方法
//电话转到服务。
_服务=新的驱动器服务(CreateAuthenticator());
//打开一个对话框供用户选择文件。
OpenFileDialog=新建OpenFileDialog();
dialog.AddExtension=true;
dialog.DefaultExt=“.txt”;
dialog.Filter=“文本文件(*.txt)|*.txt |所有文件(*.*)|*.”;
dialog.Multiselect=false;
dialog.ShowDialog();
文件体=新文件();
body.Title=System.IO.Path.GetFileName(dialog.FileName);
body.Description=“测试文档”;
body.MimeType=“text/plain”;
System.IO.Stream fileStream=dialog.OpenFile();
byte[]byteArray=新字节[fileStream.Length];
读取(byteArray,0,(int)fileStream.Length);
System.IO.MemoryStream stream=新的System.IO.MemoryStream(byteArray);
//获取现有文件的列表。。。
List fileList=Utilities.RetrieveAllFiles(_服务);
//设置一个标记以跟踪文件是否已存在于驱动器中
bool fileExists=false;
foreach(文件列表中的文件项)
{
if(item.Title==body.Title)
{
//文件已存在于驱动器中!
fileExists=true;
MessageBoxResult=System.Windows.MessageBox.Show(“您选择的文件已经存在于您的Google驱动器中。是否要覆盖它?”,“确认”,MessageBoxButton.YesNoCancel);
if(result==MessageBoxResult.Yes)
{
//是…覆盖文件
UpdateFile(_服务,item.Id,item.Title,item.Description,item.MimeType,dialog.FileName,true);
列出所有文件=实用程序。检索所有文件(_服务);
}
else if(result==MessageBoxResult.No)
{
//MessageBoxResult。这里没有代码
文件f=Utilities.insertFile(_service,System.IO.Path.GetFileName(dialog.FileName),“上载的文档”,“文本/普通”,dialog.FileName);
}
其他的
{
//MessageBoxResult。在此处取消代码
返回;
}
打破
}
}
//检查文件是否存在。如果不是,则它是一个新文件,必须上载。
如果(!fileExists)
{
File File=Utilities.insertFile(_服务,System.IO.Path.GetFileName(dialog.FileName),“上传的文档”,“文本/普通”,dialog.FileName);
var list=Utilities.RetrieveAllFiles(_服务);
}
System.Windows.MessageBox.Show(“上传完成”);

打开gdrive并将sdk设置为On。这将使应用程序能够访问gdrive帐户