Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.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#使用ServiceAccount实现的谷歌电子表格服务_C#_Google Api_Google Spreadsheet Api_Service Accounts - Fatal编程技术网

C#使用ServiceAccount实现的谷歌电子表格服务

C#使用ServiceAccount实现的谷歌电子表格服务,c#,google-api,google-spreadsheet-api,service-accounts,C#,Google Api,Google Spreadsheet Api,Service Accounts,GDataRequestFactory中的“我的应用程序用户代理”是什么。我已经完成了上面提到的代码,但仍然没有得到电子表格。我无法从谷歌文档中访问电子表格数据 if (!File.Exists(keyFilePath)) { Console.WriteLine("An Error occurred - Key file does not exist"); return null; } //Google Drive scopes Docu

GDataRequestFactory中的“我的应用程序用户代理”是什么。我已经完成了上面提到的代码,但仍然没有得到电子表格。我无法从谷歌文档中访问电子表格数据

if (!File.Exists(keyFilePath))
    {
        Console.WriteLine("An Error occurred - Key file does not exist");
        return null;
    }

    //Google Drive scopes Documentation:   https://developers.google.com/drive/web/scopes
    string[] scopes = new string[] { "https://spreadsheets.google.com/feeds", "https://docs.google.com/feeds" };  // modify your app scripts     

    var certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable);
    try
    {
        var serviceAccountCredentialInitializer =
            new ServiceAccountCredential.Initializer(serviceAccountEmail)
            {
                Scopes = new[] { "https://spreadsheets.google.com/feeds" }
            }.FromCertificate(certificate);

        var credential = new ServiceAccountCredential(serviceAccountCredentialInitializer);

        //if (!credential.RequestAccessTokenAsync(System.Threading.CancellationToken.None).Result)
        //    throw new InvalidOperationException("Access token request failed.");

        credential.RequestAccessTokenAsync(System.Threading.CancellationToken.None).Wait();

        var requestFactory = new GDataRequestFactory("My App User Agent");
        requestFactory.CustomHeaders.Add("Authorization: Bearer " + credential.Token.AccessToken);

        SpreadsheetsService service = new SpreadsheetsService("CallLog");

        service.RequestFactory = requestFactory;

        SpreadsheetQuery query = new SpreadsheetQue`enter code here`ry(); //do the job as you done it before
        SpreadsheetFeed feed = service.Query(query);

您看到的错误是什么?您的代码不清楚:电子表格查询=新建电子表格
在此处输入代码
ry();这是什么意思?我把OAuth2设置成这样。。您可以尝试使用gridspree.io之类的工具来检查内容。您知道什么是用户代理吗?useagent和ApplicationName之间有什么区别?