C# Google Drive Api将文件上载到错误的Google Drive帐户

C# Google Drive Api将文件上载到错误的Google Drive帐户,c#,asp.net-mvc,asp.net-core,google-drive-api,C#,Asp.net Mvc,Asp.net Core,Google Drive Api,我已经在我的项目中实现了文件上传到谷歌硬盘的功能。 下面是我从Google下载的凭证(客户机密钥和客户机密钥)json文件 { "web": { "client_id": "cid", "project_id": "projectid", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://accounts.google.com/o/oauth2/token"

我已经在我的项目中实现了文件上传到谷歌硬盘的功能。 下面是我从Google下载的凭证(客户机密钥和客户机密钥)json文件

{
"web": {
    "client_id": "cid",
    "project_id": "projectid",
    "auth_uri": "https://accounts.google.com/o/oauth2/auth",
    "token_uri": "https://accounts.google.com/o/oauth2/token",
    "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
    "client_secret": "cse"
}
}
下面的代码显示了使用此代码在我的机器中生成的访问令牌json文件

  using (var stream = new FileStream("drive.json", FileMode.Open, FileAccess.Read))
        {
            string credPath = System.Environment.GetFolderPath(
                System.Environment.SpecialFolder.Personal);
            credPath = System.IO.Path.Combine(credPath, ".credentials/accesstoken.json");

            credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                 Scopes,
                "a.b@gmail.com",
                CancellationToken.None,
                new FileDataStore(credPath, true)).Result;
            Console.WriteLine("Credential file saved to: " + credPath);
        }
        //create Drive API service.
        Google.Apis.Drive.v3.DriveService service = new Google.Apis.Drive.v3.DriveService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "DriveProjectName",
        });
文件上传功能运行良好,但当我将我的代码从一台电脑复制到另一台电脑,并在任何其他gmail帐户(如x。z@gmail.com)登录到那台电脑后,文件将被上传到该帐户的驱动器,而不是我的谷歌驱动器

为什么会这样?此问题是否与任何google驱动器权限或定义范围有关?需要在Google Drive或我缺少的代码中执行的任何特定设置?我在代码中定义了以下作用域

public static string[] Scopes =
{
     Google.Apis.Drive.v3.DriveService.Scope.Drive, 
     Google.Apis.Drive.v3.DriveService.Scope.DriveFile, 
     Google.Apis.Drive.v3.DriveService.Scope.DriveMetadata, 
     Google.Apis.Drive.v3.DriveService.Scope.DriveAppdata
};

有什么建议或想法吗?

这是一个网站-根据你的标签-那么如何“复制到另一台电脑”?gmail帐户“登录到该项目”是什么意思?这是一个web api代码。很抱歉,我编辑了这个问题。问题是如果我将代码从一台电脑复制到另一台电脑,并在另一台电脑上运行我的项目代码,如果有其他gmail帐户(例如x)。z@gmail.com)已登录到该电脑,该文件被上传到该帐户的驱动器,而不是我的谷歌驱动器(例如,我的gmail帐户是a。b@gmail.com我希望将文件上载到此帐户驱动器上)