我熟悉在Google云端硬盘中创建文件夹的过程,但是我正在研究使用异步方法进行此操作。但是,这样做时,我不确定如何获取明确添加到要返回的字段中的字段。
我的代码如下:
private Task<Google.Apis.Drive.v3.Data.File> CreateGoogleDriveFolderAsync(DriveService service, string foldername, string parent_id = null)
{
IList<string> parent_ids = new List<string>();
Google.Apis.Drive.v3.Data.File folder = new Google.Apis.Drive.v3.Data.File
{
Name = foldername
, MimeType = "application/vnd.google-apps.folder"
, Description = "Client Name: blah\nUser: Rudy\n"
};
var insert = service.Files.Create(folder);
// The field I'd like to get somewhere.
insert.Fields = "id";
var task = insert.ExecuteAsync();
task.ContinueWith(t =>
{
// NotOnRanToCompletion - this code will be called if the upload fails
Console.WriteLine("Failed to create folder \"{0}\": " + …Run Code Online (Sandbox Code Playgroud) 我有一个正在运行的计划任务,但似乎没有用。此任务执行一个批处理文件。批处理文件仅包含一行:
wscript c:\myfolder/myscript.vbs
Run Code Online (Sandbox Code Playgroud)
该VBScript文件启动命令提示符,执行vpncli,睡眠一分钟,然后继续建立连接,将用户名/密码发送到命令行窗口。
从命令提示符窗口运行批处理文件时,此方法工作正常,但使用计划任务无法成功。运行任务的帐户是服务托管帐户。运行任务之后,我在一个单独的命令行窗口中进行检查vpncli,然后看到连接仍然断开。
要解决此问题,在计划任务中执行批处理文件时必须考虑什么?
以下是我用于在CMD Shell中执行的部分代码。执行以下子例程:
Sub VPN_open
VPN_Profile = "vpn.myhost.com"
VPN_User = "USERNAME"
' If the password contains special characters, enclose the characters in curly braces {}.
VPN_Password = "PASSWORD"
oShell.Run "cmd"
WScript.Sleep 100
oShell.AppActivate "C:\Windows\System32\cmd.exe"
oShell.SendKeys "vpncli connect " & VPN_Profile & "~"
WScript.Sleep 10000
oShell.SendKeys VPN_User & "~"
WScript.Sleep 5000
oShell.SendKeys VPN_Password & "~"
WScript.Sleep 10000
oShell.SendKeys "exit~"
End Sub 'VPN_open
Run Code Online (Sandbox Code Playgroud) 尝试创建文件夹并设置其权限时出现以下错误。它无需传递文件元数据中的权限即可工作。
但我想创建具有特定用户权限的文件夹,每个用户都有自己的 g 邮件帐户。我怎样才能做到这一点?谢谢!
错误信息:
代码:
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v3;
using Google.Apis.Drive.v3.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DriveQuickstart
{
class Program
{
// If modifying these scopes, delete your previously saved credentials
// at ~/.credentials/drive-dotnet-quickstart.json
static string[] Scopes = { DriveService.Scope.Drive };
static string ApplicationName = "Drive API .NET Quickstart";
static void Main(string[] args)
{
UserCredential credential;
using (var stream =
new FileStream("client_secret.json", FileMode.Open, FileAccess.ReadWrite))
{ …Run Code Online (Sandbox Code Playgroud)