错误:解析值时遇到意外字符:e。路径'',第0行,位置0。
我正在使用Google .Net客户端库来访问Google驱动器API v3,尤其是Google.Apis.Drive.v3程序包。我正在通过C#授权使用“服务帐户”。
使用p12密钥进行授权是没有问题的。但是,建议使用JSON,并保留p12格式以实现向后兼容。
我从Google Developers Console下载了JSON文件,并尝试使用以下代码进行授权:
public static Google.Apis.Drive.v3.DriveService AuthenticateServiceAccountJSON(string keyFilePath) {
// check the file exists
if (!File.Exists(keyFilePath)) {
Console.WriteLine("An Error occurred - Key file does not exist");
return null;
}
string[] scopes = new string[] { DriveService.Scope.Drive, // view and manage your files and documents
DriveService.Scope.DriveAppdata, // view and manage its own configuration data
DriveService.Scope.DriveFile, // view and manage files created by this app
DriveService.Scope.DriveMetadataReadonly, // view metadata for files
DriveService.Scope.DriveReadonly, // view files …Run Code Online (Sandbox Code Playgroud) c# google-api google-drive-api google-api-dotnet-client service-accounts