Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.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#_Google Api_Google Drive Api_Google Api Dotnet Client_Google Oauth - Fatal编程技术网

C# &引用;“访问被拒绝”;从一台电脑,而不是另一台电脑

C# &引用;“访问被拒绝”;从一台电脑,而不是另一台电脑,c#,google-api,google-drive-api,google-api-dotnet-client,google-oauth,C#,Google Api,Google Drive Api,Google Api Dotnet Client,Google Oauth,我正在使用以下代码创建到Google Drive API的连接: using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.ReadWrite)) { string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); credPath = Pa

我正在使用以下代码创建到Google Drive API的连接:

using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.ReadWrite))
{
      string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
      credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json");

      try
      {
            this.credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                  GoogleClientSecrets.Load(stream).Secrets,
                  Scopes,
                  "Google Drive Import",
                  CancellationToken.None,
                  new FileDataStore(credPath, true)).Result;
      }
      catch(Exception ex)
      {
            log.Error("Exception caught in creating Drive connection" + ex.InnerException.Message);
      }
}
从我的PC创建连接(在Win10中用VS 2015编译/执行)似乎可以,但当我从服务器尝试(在Windows server 2012 R2中用VS 2015编译/执行)时,调试时我会遇到“拒绝访问”的情况。我在这里做错了什么


到目前为止,我已经比较了两台电脑上Fiddler的日志,我看到了两台工作站上所有200个结果代码。

@DaImTo帮助我解决了这个问题。将文件写入credPath位置的权限有问题。在评论中,您会找到一个链接,帮助更改到自定义数据存储:。再次感谢@DaImTo。

@DaImTo h请帮助我解决这个问题。将文件写入credPath位置的权限有问题。在注释中,您会找到一个链接,帮助更改到自定义数据存储:。再次感谢@DaImTo。

您是否在服务器上作为已安装的应用程序运行此应用程序?我不这么认为。它们都使用源代码管理中的相同代码。让我y这是什么类型的应用程序?您正在使用的代码用于已安装的应用程序,例如,它不会作为web应用程序在IIS上运行。请检查您是否有权访问服务器上的credPath。您需要能够写入该目录。在运行时,请检查您是否有权在需要时读取client_secret.jsonIf可以移动数据存储的位置。如果仍然不起作用,请告诉我您得到的完整错误。您是在服务器上作为已安装的应用程序运行此应用程序吗?我不这么认为。它们都使用来自源代码管理的相同代码。让我重试这是什么类型的应用程序?您使用的代码是用于已安装的应用程序的,它是例如,我不会以web应用程序的形式在IIS上工作。请检查您是否有权访问服务器上的credPath。您需要能够写入该目录。在执行此操作时,请检查您是否有权读取client_secret.json。如果需要,您可以移动数据存储的位置。如果仍然不起作用,请告诉我您遇到的全部错误滴答声。