Я создал таблицу Google с помощью API Google API, как показано ниже. Я не получаю никаких исключений, и из кода i также удалось получить идентификатор файла. Но когда я смотрю на Google Drive, я не вижу файл. Есть ли что-то, что я должен сделать, чтобы уведомить Google Drive. Я тоже обновил свой диск. Но бесполезно. Есть идеи?новая таблица не отображается на Google Диске с использованием .NET API
Я аутентифицирован мою службу, как показано ниже:
authenticate.cs
public class SerivceAccount
{
private const string ServiceAccountEmail = "[email protected]";
private static readonly X509Certificate2 Certificate = new X509Certificate2("ADExpress.p12", "notasecret", X509KeyStorageFlags.Exportable);
readonly ServiceAccountCredential _credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(ServiceAccountEmail)
{
Scopes = new[]
{
"https://spreadsheets.google.com/feeds",
DriveService.Scope.Drive,
"https://www.googleapis.com/auth/drive.file"
}
}.FromCertificate(Certificate));
public bool Authenticate()
{
var isAuthenticated = false;
try
{
if (!_credential.RequestAccessTokenAsync(System.Threading.CancellationToken.None).Result)
throw new InvalidOperationException("Access token request failed.");
isAuthenticated = true;
}
catch (Exception e)
{
Console.WriteLine("Exception in Authenticating " + e.ToString());
}
return isAuthenticated;
}
public ServiceAccountCredential Credential
{
get { return _credential; }
}
}
main.cs
var account = new SerivceAccount();
if (account.Authenticate())
{
FilesResource.InsertRequest request = service.Files.Insert(new Google.Apis.Drive.v2.Data.File()
{
Title = "Test",
Description = "Test",
MimeType = "application/vnd.google-apps.spreadsheet"
});
var file = request.Execute();
Console.WriteLine("File ID: " + file.Id);
}
Как работает служба аутентификации? – DaImTo
@DalmTo, я обновил свой вопрос с помощью запроса на аутентификацию. –