Ben başka bir kullanıcı adına hareket eden hizmet hesabını kullanarak bir DriveService oluşturma denedim işe yaramaz.AssertionFlowClient ServiceAccountCredential kullanmaya çalışıyor, depreceated ama
ben kopyaladıktan google belgelerine bu kod burada https://developers.google.com/drive/delegation
static DriveService BuildService() {
X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.Exportable);
var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate)
{
ServiceAccountId = SERVICE_ACCOUNT_EMAIL,
Scope = DriveService.Scopes.Drive.GetStringValue(),
};
var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState);
return new DriveService(auth);
}
buldum ama projeyi inşa etmeye çalışırken bu uyarıyı alıyorum:
Uyarı 4 'Google.Apis.Authentication.OAuth2. DotNetOpenAuth.AssertionFlowClient 'artık kullanılmıyor:' AssertionFlowClient artık desteklenmiyor ve 1.7.0-beta kaldırılacak gidiyor. Yeni Google.Apis.Auth Nuget paketinden ServiceAccountCredential kullanmayı düşünün.'
ve ben de bu hatayı alıyorum:
Hatası 11 Tartışma 1: 'Google.Apis.Authentication.OAuth2.OAuth2Authenticator' dan dönüştüremezsiniz 'Google.Apis.Services.BaseClientService.Initializer'
için Sonra ServiceAccountCredential googled ve (bu sayfadan türetilen: https://code.google.com/p/google-api-dotnet-client/wiki/OAuth2#Service_Accounts) bu kod ile sona erdi
static DriveService BuildService() {
X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(SERVICE_ACCOUNT_EMAIL)
{
User = "[email protected]",
Scopes = new[] { DriveService.Scope.DriveFile }
}.FromCertificate(certificate));
var service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Drive API Sample",
});
return service;
}
her şeyin iyi görünüyor bu kodu oluşturmak için deneyin, ama onu çalıştırdığınızda aşağıdaki hatayı alıyorum. Det går inte att hitta det begärda objektet:
türü 'System.Security.Cryptography.CryptographicException' Ilk şansını istisna
mscorlib.dlloluştu Ek bilgi. (Çevrilen: İstenilen nesne bulunamıyor)
Bu özel durum için bir işleyici varsa, program güvenli bir şekilde devam edebilir.
X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.Exportable);
Herkes herhangi bir fikir var:
hata bu hatta meydana?
tür bir işlenmeyen özel durum 'Google.Apis.Auth.OAuth2.Responses.TokenResponseException':
{
Console.WriteLine("Drive API - Service Account");
Console.WriteLine("==========================");
String serviceAccountEmail = "<some email>@developer.gserviceaccount.com";
var certificate = new X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
User = "<someuser>@<mydomain>.mygbiz.com",
Scopes = new[] { DriveService.Scope.Drive }
}.FromCertificate(certificate));
// Create the service.
var service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "DrvMgr",
});
Console.WriteLine("Executing listing");
FileList UserFiles = service.Files.List().Execute();
hata mesajını alıyorum:
Güncelleme 2013 31 Ekim Bu kodu denedi Hata: "ACCESS_DENIED", Açıklama:
bilgiye Google.Apis.dll oluştu "", Uri: ""
Maalesef hayır! Yol kontrol edildi ve tüm oki (C: \ temp \ tuşuna bastım.p12) Ve satırı şu şekilde değiştirdiğimde: X509Certificate2 certificate = new X509Certificate2 (@ "C: \ temp \ key.p12", "notasecret", X509KeyStorageFlags.Exportable); aynı hata oluşuyor: Yolunu değiştirirseniz, örneğin @ "C: \ tamp \ key.p12" Başka bir hata iletisi alıyorum: 'System.Security.Cryptography.CryptographicException' türünde bir ilk fırsat istisnası oluştu. mscorlib.dll Ek bilgi: Bilgi edinin: hitta sökvägen. (Çevrilmiş: "Yol bulunamıyor") – JoBe
Hala çalışamıyorum. Bir çeşit sürüm uyuşmazlığı olabilir mi? Ayrıca, cevabınızda sağladığınız Bağlantı, AssertionFlowClient'i kullanır, ancak benim soruda belirttiğim gibi, artık desteklenmediğine dair bir uyarı aldım. Bir şey mi eksik? – JoBe
Üzgünüz, bu bağlantıyı deneyin: https://code.google.com/p/google-api-dotnet-client/source/browse/Plus.ServiceAccount/?repo=samples. README dosyasını izleyebilir ve bu örneğin beklendiği gibi çalıştığını doğrulayabilir misiniz? Ve .. sadece doğrulamak için - Google API Konsolundan indirdiğiniz dosyayı bu konuma kopyaladınız mı (C: \ Temp \ key.p12)? – peleyal