Google电子表格会引发403

时间:2017-04-12 13:46:29

标签: c# google-sheets

我正在使用c#访问googlespread表。但是我收到错误 Google.Apis.Requests.RequestError 用户对此配置文件没有足够的权限。 [403] 错误[ 消息[用户对此配置文件没有足够的权限。]位置[ - ]原因[insufficientPermissions]域[global] ]

这是我的代码:

string applicationName = "DemoSample";

            var keyfilePath = @"C:\Users\prasanthi.kota\Documents\Visual Studio 2015\Projects\DemoSheetsApplication\DemoSheetsApplication\key.p12";

            var serviceaccountemail = "demo-280@demosample-164413.iam.gserviceaccount.com";

            var certificate = new X509Certificate2(keyfilePath, "notasecret", X509KeyStorageFlags.Exportable);

            ServiceAccountCredential credential = new ServiceAccountCredential(
              new ServiceAccountCredential.Initializer(serviceaccountemail)
              {
                  Scopes = new[] { "https://spreadsheets.google.com/feeds" }
              }.FromCertificate(certificate));

            var service = new SheetsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = applicationName,
            });
            Console.WriteLine("service " + service);

            String spreadsheetId = "10QLUcBhkGK_-cpRJTbNky9v_fhShWRmZm7P5rloELf4";

            String range = "Sheet1!A:D";

            SpreadsheetsResource.ValuesResource.GetRequest request = service.Spreadsheets.Values.Get(spreadsheetId, range);

            ValueRange response = request.Execute();

            IList<IList<Object>> values = response.Values;

            if (values != null && values.Count > 0)
            {
                foreach (var row in values)
                {
                    // Print columns A and E, which correspond to indices 0 and 4.
                    Console.WriteLine("{0}, {1}", row[0], row[1]);
                }
            }
            else
            {
                Console.WriteLine("No data found.");
            }
            Console.Read();

我收到错误&#34; request.Execute()&#34;

0 个答案:

没有答案