문제

When using this code In my Visual Stuidio Win form project.

var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, ClientId, ClientSecret);

I am getting a message

NativeApplicationClient is not supported any more and it's going to be removed in 1.7.0-beta. Consider using the new Google.Apis.Auth NuGet package which supports .NET 4, .NET for Windows Store apps, Windows Phone 7.5 and 8 and Portable Class Libraries as well

I am using

install-package Google.Apis.Authentication -pre

If i add Google.apis.auth instead of Google.Apis.Authentication it doesnt apeare to even have NativeApplicationClient. But I cant find any information on what I'm suposed to be using insted of NativeApplicationClient.

도움이 되었습니까?

해결책

Yes i got it working.

Install these packages in your project

pm> install-package google.apis -pre
pm> install-package google.apis.drive.v2 -pre

Add these usings

using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using System.IO;
using Google.Apis.Drive.v2;
using Google.Apis.Util.Store;
using System.Threading;

private void Form1_Load(object sender, EventArgs e)
 {
 UserCredential credential;
 using (var stream = new FileStream("client_secrets.json", FileMode.Open,
                                 FileAccess.Read))  {
    GoogleWebAuthorizationBroker.Folder = "Tasks.Auth.Store";
    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
    GoogleClientSecrets.Load(stream).Secrets,
    new[] { DriveService.Scope.Drive,
            DriveService.Scope.DriveFile },
    "user",
    CancellationToken.None,
    new FileDataStore("Drive.Auth.Store")).Result;
    }  

}

For google drive i would then create a drive service. You send all the calls against the service. Works the same for google analytics.

BaseClientService service = new DriveService(new BaseClientService.Initializer()
 {
 HttpClientInitializer = credential,
 ApplicationName = "Drive API Sample",
 });

I expain it all in a blog post: http://daimto.com/google-oauth2-csharp/

If you figuer out how to feed it a stored refrshToken and use that let me know i'm still trying to figuer that out.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top