C# 谷歌电子数据表发布403

C# 谷歌电子数据表发布403,c#,google-sheets,C#,Google Sheets,我正在使用c#访问Google电子表格。但是我得到了一个错误,Google.api.Requests.RequestError 用户对此配置文件没有足够的权限。[403] 错误[ 消息[用户对此配置文件没有足够的权限。]位置[-]原因[权限不足]域[全局] ] 这是我的密码: string applicationName = "DemoSample"; var keyfilePath = @"C:\Users\prasanthi.kota\Documents\Visua

我正在使用c#访问Google电子表格。但是我得到了一个错误,Google.api.Requests.RequestError 用户对此配置文件没有足够的权限。[403] 错误[ 消息[用户对此配置文件没有足够的权限。]位置[-]原因[权限不足]域[全局] ]

这是我的密码:

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();
string applicationName=“DemoSample”;
var keyfilePath=@“C:\Users\prasanthi.kota\Documents\Visual Studio 2015\Projects\DemoSheetsApplication\DemoSheetsApplication\key.p12”;
var serviceaccountemail=“演示-280@demosample-164413.iam.gserviceaccount.com”;
var证书=新的X509Certificate2(keyfilePath,“notasecret”,X509keystrageFlags.Exportable);
ServiceAccountCredential credential=新ServiceAccountCredential(
新ServiceAccountCredential.初始值设定项(serviceaccountemail)
{
作用域=新[]{”https://spreadsheets.google.com/feeds" }
}.FromCertificate(证书));
var service=new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer=凭证,
ApplicationName=ApplicationName,
});
控制台写入线(“服务”+服务);
字符串spreadsheetId=“10QLUcBhkGK_u2;-cpRJTbNky9v_fhShWRmZm7P5rloELf4”;
字符串range=“Sheet1!A:D”;
电子表格sresource.ValuesResource.GetRequest request=service.Spreadsheets.Values.Get(电子表格ID,范围);
ValueRange响应=请求。执行();
IList值=响应值;
if(值!=null&&values.Count>0)
{
foreach(值中的var行)
{
//打印对应于索引0和4的A列和E列。
WriteLine(“{0},{1}”,行[0],行[1]);
}
}
其他的
{
Console.WriteLine(“未找到数据”);
}
Console.Read();
我在“请求.执行()”时出错