我想在Google表格中编写单个单元格。我使用新的API(v3)和OAuth2进行身份验证。我使用我的JSON密钥文件进行授权和身份验证。我构建SpreadsheetService,然后创建一个查询,然后创建一个feed。创建Feed时出现"Parsing failed (root element missing)"
错误。我在developers.google.com和其他帖子和解决方案中阅读了整个文档,但我似乎缺少一个关键元素。对我来说,我似乎无法通过"我对Spreadsheetservice的身份验证。这是我的代码:
static string[] SCOPES = { DriveService.Scope.Drive };
static string APP_NAME = "Excel2Sheets";
static void Main(string[] args)
{
/authentication using JSON file
UserCredential credential;
using (var stream =
new FileStream("path_to_my_fyle",
FileMode.Open, FileAccess.Read))
{
string credPath = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.Personal);
credPath = Path.Combine(credPath, ".credentials/drive-dotnet-quickstart.json");
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
SCOPES,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Creds save to: {0}", credPath);
}
//building Drive Service
var driveService = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = APP_NAME,
});
SpreadsheetsService sheetService = new SpreadsheetsService("Excel2Sheets");
SpreadsheetQuery query = new SpreadsheetQuery();
SpreadsheetFeed feed = sheetService.Query(query);

早些时候,我可以正确地做到这一点,但后来我使用API v2解决了刷新令牌及其超时问题。这就是为什么我切换到v3。