小编Mar*_*cel的帖子

Google Drive API v3使用JSON而不是P12(服务帐户)-意外字符

错误:解析值时遇到意外字符: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

5
推荐指数
1
解决办法
2778
查看次数