C#.net的Google云端硬盘示例代码无法构建

时间:2014-04-12 17:46:58

标签: c# .net windows-store-apps google-drive-api

here获取的以下代码无法构建抛出以下错误

Argument 1: cannot convert from 'Google.Apis.Auth.OAuth2.ClientSecrets' to 'System.Uri' 

代码:

using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
/* Microsoft Live SDK */
using Microsoft.Live;
/* Google Drive SDK*/
using Google;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;
using Google.Apis.Services;

public sealed class GoogleDrive
    {
        GoogleDrive()
        {
            UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                new ClientSecrets
                {
                    ClientId = "CLIENT_ID_HERE",
                    ClientSecret = "CLIENT_SECRET_HERE",
                },
                new[] { DriveService.Scope.Drive },
                "user",
                CancellationToken.None).Result;

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

    }

根据hereAuthorizeAsync类中应该有5个重载的GoogleWebAuthorizationBroker函数,但我所指的api只包含一个。

我使用nuget manager添加google drive v2 sdk

的引用

GoogleWebAuthorizationBroker班。

#region Assembly Google.Apis.Auth.PlatformServices.dll, v1.8.1.31703
// C:\Users\UserName\Documents\Visual Studio 2013\Projects\ProjectName\packages\Google.Apis.Auth.1.8.1\lib\netcore45\Google.Apis.Auth.PlatformServices.dll
#endregion

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;

namespace Google.Apis.Auth.OAuth2
{
    // Summary:
    //     A helper utility to manage the authorization code flow.
    public class GoogleWebAuthorizationBroker
    {
        public GoogleWebAuthorizationBroker();

        // Summary:
        //     Asynchronously authorizes the specified user.
        //
        // Parameters:
        //   clientSecretsUri:
        //     The client secrets URI.
        //
        //   scopes:
        //     The scopes which indicate the Google API access your application is requesting.
        //
        //   user:
        //     The user to authorize.
        //
        //   taskCancellationToken:
        //     Cancellation token to cancel an operation.
        //
        // Returns:
        //     User credential.
        //
        // Remarks:
        //     It uses Google.Apis.Util.Store.StroageDataStore as the flow's data store
        //     by default.
        [DebuggerStepThrough]
        public static Task<UserCredential> AuthorizeAsync(Uri clientSecretsUri, IEnumerable<string> scopes, string user, CancellationToken taskCancellationToken);
    }
}

0 个答案:

没有答案