C#中:谷歌驱动器:谷歌apis.services是否缺少程序集或参考驱动器、程序、apis、谷歌

2023-09-03 04:27:14 作者:淡嘫①笶

我想使用google.drive使用快速入门例如.NET。我已经安装了经过的NuGet的dll,但我收到以下错误,我很想念参考或组件google.apis.service。任何帮助,将AP preciated

 使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;
使用DotNetOpenAuth.OAuth2;
使用Google.Apis.Authentication.OAuth2;
使用Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
使用Google.Apis.Drive.v2;
使用Google.Apis.Drive.v2.Data;
使用Google.Apis.Util;
使用Google.Apis.Services;

公共部分类Default3:System.Web.UI.Page
{
    保护无效的Page_Load(对象发件人,EventArgs的)
    {

    }
    保护无效的button1_Click(对象发件人,EventArgs的)
    {

         字符串CLIENT_ID =some_id;
            字符串CLIENT_SECRET =some_secret;

            //注册认证和创建服务
            VAR提供商=新NativeApplicationClient(GoogleAuthenticationServer.Description,CLIENT_ID,CLIENT_SECRET);
            VAR AUTH =新OAuth2Authenticator< NativeApplicationClient>(供应商,GetAuthorization);
            VAR的服务=新DriveService(新BaseClientService.Initializer()
            {
                身份验证= AUTH
            });

            文件主体=新的文件();
            body.Title =我的文档;
            body.Description =测试文档;
            body.MimeType =text / plain的;

            字节[]的字节数组= System.IO.File.ReadAllBytes(文档.txt);
            System.IO.MemoryStream流=新System.IO.MemoryStream(字节阵列);

            FilesResource.InsertMediaUpload请求= service.Files.Insert(机身,流,text / plain的);
            request.Upload();

            文件fil​​e = request.ResponseBody;
            Console.WriteLine(文件ID:+ file.Id);
            Console.WriteLine(preSS Enter结束这个过程。);
            到Console.ReadLine();
        }

        私有静态IAuthorizationState GetAuthorization(NativeApplicationClient ARG)
        {
            //获取身份验证网址:
            IAuthorizationState状态=新AuthorizationState(新[] {DriveService.Scopes.Drive.GetStringValue()});
            state.Callback =新的URI(NativeApplicationClient.OutOfBandCallbackUrl);
            乌里authUri = arg.RequestUserAuthorization(州);

            //请求从用户授权(通过打开浏览器窗口):
            的Process.Start(authUri.ToString());
            Console.Write(授权code:);
            字符串AUTH code =到Console.ReadLine();
            Console.WriteLine();

            //使用授权code。获取访问令牌:
            返回arg.ProcessUserAuthorization(AUTH code,状态);
        }
    }
 

解决方案

尝试从我们的样品库运行我们的Drive.Sample - https://$c$c.google.com/p/google-api-dotnet-client/source/browse/?repo=samples#hg%2FDrive.Sample.你可以看到一个工作实现有(也包括媒体的上传和下载code)。

尝试重新开始并安装以下两个包(我不知道,如果你已经这样做了): Google.Apis.Drive.v2 - https://www.nuget.org/包/ Google.Apis.Drive.v2 / Google.Apis.Authetnication - https://www.nuget.org/packages/Google.Apis .Authentication

更新(2014年1月22日):

我们重新实现OAuth的2.0库和几个月前去除DotNetOpenAuth的依赖。 您可以在公告博客阅读更多关于它。搜索专门为1.6.0-beta版本。

插件谷歌驱动器app下载 插件谷歌驱动器手机版下载 手机插件谷歌驱动器下载

您也应该参加我们的OAuth 2.0页面一看 - 的 HTTPS://$c$c.google.com/p/google-api-dotnet-client/wiki/OAuth2

另外一个很好的参考,是我们的样本库。所有样品已被升级为使用新Google.Apis.Auth pacakge

i am trying to use google.drive for .net using the quickstart example. i have installed dlls via nuget, but am receiving the following error that i am missing a reference or assembly for google.apis.service. any help would be appreciated

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);
        }
    }

解决方案

Try to run our Drive.Sample from our samples repository - https://code.google.com/p/google-api-dotnet-client/source/browse/?repo=samples#hg%2FDrive.Sample. You can see a working implementation there (it also includes media upload and download code).

Try to start over again and install the following two packages (I'm not sure if you already did so): Google.Apis.Drive.v2 - https://www.nuget.org/packages/Google.Apis.Drive.v2/ Google.Apis.Authetnication - https://www.nuget.org/packages/Google.Apis.Authentication

UPDATE (January 22nd 2014):

We reimplemented the OAuth 2.0 library and removed the dependency in DotNetOpenAuth several months ago. You can read more about it in the announcements blog. Search specifically for the 1.6.0-beta release.

You should also take a look in our OAuth 2.0 page - https://code.google.com/p/google-api-dotnet-client/wiki/OAuth2.

Another good reference is our samples repository. All the samples had been upgraded to use the new Google.Apis.Auth pacakge.