Ошибка: обнаружен непредвиденный символ при синтаксическом анализе значения: e. Путь '', строка 0, позиция 0.
Я использую клиентскую библиотеку Google .Net для доступа к API диска Google v3, в частности к Пакет Google.Apis.Drive.v3. Я разрешаю использовать «Учетную запись службы» с C#.
Авторизация по ключу p12 не проблема. Однако рекомендуется использовать JSON, а формат p12 поддерживается для обратной совместимости.
Я скачал JSON-файл из Google Developers Console и попытался авторизоваться с помощью следующего кода:
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 and documents on your drive
DriveService.Scope.DriveScripts }; // modify your app scripts
try {
using (var stream = new FileStream(keyFilePath, FileMode.Open, FileAccess.Read)) {
var credential = GoogleCredential.FromStream(stream);
if (credential.IsCreateScopedRequired) {
credential.CreateScoped(scopes);
}
// Create the service.
Google.Apis.Drive.v3.DriveService service = new Google.Apis.Drive.v3.DriveService(new BaseClientService.Initializer() {
HttpClientInitializer = credential,
ApplicationName = "MyDrive",
});
return service;
}
} catch (Exception ex) {
Console.WriteLine(ex.InnerException);
return null;
}
}
Я просмотрел файл JSON в блокноте, и он кажется зашифрованным.
"ewogICJ0eXBlIjogInNlcnZpY2VfYWNjb3VudCIsCiAgInByb2plY3RfaWQiOiAicmFkaWFudC1tZXJjdXJ5LTEyMjkwNyIsCiAgIn.........."
Можно ли продолжать использовать P12?