c#: google drive : google-apis.Dienstleistungen fehlt ein Montage-oder Referenz
ich versuche, mit google.Antrieb für .net mit den quickstart-Beispiel. ich habe installiert, die dlls über nuget, aber erhalte die folgende Fehlermeldung, dass ich eine Referenz fehlt oder Montage für google.apis.service. jede Hilfe würde geschätzt
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetOpenAuth.OAuth2;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;
using Google.Apis.Util;
using Google.Apis.Services;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
String CLIENT_ID = "some_id";
String CLIENT_SECRET = "some_secret";
//Register the authenticator and create the service
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET);
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
var service = new DriveService(new BaseClientService.Initializer()
{
Authenticator = auth
});
File body = new File();
body.Title = "My document";
body.Description = "A test document";
body.MimeType = "text/plain";
byte[] byteArray = System.IO.File.ReadAllBytes("document.txt");
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain");
request.Upload();
File file = request.ResponseBody;
Console.WriteLine("File id: " + file.Id);
Console.WriteLine("Press Enter to end this process.");
Console.ReadLine();
}
private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
{
//Get the auth URL:
IAuthorizationState state = new AuthorizationState(new[] { DriveService.Scopes.Drive.GetStringValue() });
state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
Uri authUri = arg.RequestUserAuthorization(state);
//Request authorization from the user (by opening a browser window):
Process.Start(authUri.ToString());
Console.Write(" Authorization Code: ");
string authCode = Console.ReadLine();
Console.WriteLine();
//Retrieve the access token by using the authorization code:
return arg.ProcessUserAuthorization(authCode, state);
}
}
- Nicht setzen die geheimen Sachen in den offen!
- An welcher Stelle bekommst du die Ausnahme? Oder ist es während der Kompilierung?
Du musst angemeldet sein, um einen Kommentar abzugeben.
Versuchen unser Antrieb.Beispiel aus unserer Muster-repository - https://code.google.com/p/google-api-dotnet-client/source/browse/?repo=samples#hg%2FDrive.Sample. Sie können sehen, eine funktionierende Implementierung gibt (es enthält auch media-upload-und download-code).
Versucht immer wieder zu starten und die Installation der folgenden zwei Pakete (ich bin mir nicht sicher, ob Sie schon so):
Google.Apis.- Laufwerk.v2 - https://www.nuget.org/packages/Google.Apis.Drive.v2/
Google.Apis.Authetnication - https://www.nuget.org/packages/Google.Apis.Authentication
UPDATE (22. Januar 2014):
Wir reimplementiert die OAuth-2.0-Bibliothek und entfernt die Abhängigkeit in DotNetOpenAuth vor einigen Monaten.
Sie können mehr darüber Lesen Sie in der Ankündigungen blog. Suche speziell für das 1.6.0-beta-Version.
Sollten Sie auch einen Blick in unsere OAuth 2.0-Seite - https://code.google.com/p/google-api-dotnet-client/wiki/OAuth2.
Andere gute Referenz ist unsere Proben-repository. Alle Proben wurden aufgerüstet, um die Nutzung der neuen Google.Apis.Auth-Paket.