谷歌账户问题-无法在电子表格上书写

本文关键字:电子表格 书写 问题 谷歌 | 更新日期: 2023-09-27 18:01:15

我正在开发一个必须在谷歌电子表格上编写的应用程序。我的应用程序过去工作良好,直到两个月前谷歌更改为Auth API。遵循与新流程的链接。

Google.GData.Client.GDataRequestException-旧代码中的身份验证突然失败

我有一个谷歌账户me@company.com由我老板的账户管理company@gmail.com.

我想写一个名为"银行详细信息"的电子表格,从我的老板账户分享给我。(标题为"mycompany"(

我从我的帐户生成了一个key.p12,它运行良好,我可以写。

现在奇怪的是,当我自己创建电子表格时(所有者是"我",我的应用程序找不到文件并返回错误消息。

我从老板的账户生成了一个key.p12,但它仍然找不到老板创建的电子表格,所以从他的角度来看,所有者是"我"。

结论:

  • 我找到了老板和我的钥匙共享的电子表格,我可以在里面写字
  • 我找不到我用密钥创建的文件
  • 我的应用程序找不到老板用密钥创建的文件

这是我的代码,但我不认为问题来自这里。

 string keyFilePath;    // found in developer console
                string serviceAccountEmail;
                if (test == true) 
                {
                    keyFilePath = @"C:'keyTEST.p12";
                    serviceAccountEmail = "me@developer.gserviceaccount.com";// found in developer console
                }
                else
                {
                    keyFilePath = @"C:'key.p12";
                    serviceAccountEmail ="company@developer.gserviceaccount.com";
                }
                var certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable);
                ServiceAccountCredential credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmail) //create credential using certificate
                {
                    Scopes = new[] { "https://spreadsheets.google.com/feeds/" } //this scopr is for spreadsheets, check google scope FAQ for others
                }.FromCertificate(certificate));
                credential.RequestAccessTokenAsync(System.Threading.CancellationToken.None).Wait(); //request token
                var requestFactory = new GDataRequestFactory("Some Name");
                requestFactory.CustomHeaders.Add(string.Format("Authorization: Bearer {0}", credential.Token.AccessToken));
                SpreadsheetsService myService = new SpreadsheetsService("Bank Details"); //create your old service
                myService.RequestFactory = requestFactory; //add new request factory to your old service
                myService.setUserCredentials(email, password);

                // Instantiate a SpreadsheetQuery object to retrieve spreadsheets.
                SpreadsheetQuery query = new SpreadsheetQuery();
                // Make a request to the API and get all spreadsheets.
                SpreadsheetFeed feed = myService.Query(query);
                SpreadsheetEntry fileEntry = feed.Entries.Cast<SpreadsheetEntry>().FirstOrDefault(entry => entry.Title.Text == spreadSheetName);
                SpreadsheetEntry spreadsheet = (SpreadsheetEntry)fileEntry;
                if (feed.Entries.Count == 0)
                {
                    Console.WriteLine("None");
                }

谷歌账户问题-无法在电子表格上书写

您需要在工作表中共享电子邮件"company@developer.gserviceaccount.com"或"me@developer.gserviceaccount.com".