使用.NET谷歌驱动器脱机访问 [英] Google drive Offline Access using .net

查看:184
本文介绍了使用.NET谷歌驱动器脱机访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要来访问我的应用程序的谷歌驱动器。 的功能,我需要的是在特定用户第一次验证应用程序,我需要从API,我可以存储在我们的终端一些信息,然后经过每当用户想要访问谷歌的驱动器,他还没有到签约到谷歌的驱动器,并且也没有进行认证的应用程序,但使用的用户的储存信息,它自动验证的驱动器访问的用户。 我见过很多例子与离线访问,但没有能够解决我的目的。 在相同的功能,在下面的网站上的谷歌驱动器访问。 https://www.multcloud.com/

I need to have to access the google drive from my application. The functionality,i need is when particular user first authenticate the application, i need to have some information from the API, which i can store at our end, and then after whenever user want to access the google drive, he has not to signing to the google drive, and also not to authenticate the application, but using stored information of the user, it automatically authenticate the user for the drive access. I have seen many examples with the offline access, but not able to solve my purpose. The same functionality with the google drive access at the below site. https://www.multcloud.com/

请人给我做了这样或那样的一些例子能满足上述要求。

Anyone please give me the way to do or some example which can fulfill above requirement.

推荐答案

我和连接谷歌驱动器与我的应用程序相同的问题,但现在我发现了一个解决方案,它绝对是工作对我罚款。谷歌客户端的lib将处理所有的you.Download的NuGet包Google.GData.Client和Google.GData.Documents。

I had Same Problem with connecting Google Drive with my Application, but now I found one solution which absolutely Working fine for me. Googles Client lib will handle all that for you.Download nuget Package Google.GData.Client and Google.GData.Documents.

下面我code

 parameters = new OAuth2Parameters()
                {
                    ClientId = "CLIENT_ID",
                    ClientSecret = "CLIENT_SECRET",
                    RedirectUri = currentURL,//"http://localhost:6600/Home.html",
                    Scope = "https://docs.google.com/feeds/ ",
                    State = "documents",
                    AccessType = "offline",  // offline means it creats a refreshtoken 
                    TokenExpiry = DateTime.Now.AddYears(1)
                };
                string url = Google.GData.Client.OAuthUtil.CreateOAuth2AuthorizationUrl(parameters);

1),在这里用户应与他的帐户登录,从而使这里重定向页面 2)当你回到你的页面(的Oauth重定向页) 3)再从URL code和状态(查询字符串) 4)发送到服务器(页面加载事件) 5)写以下code Page_Load事件(首次得到code变量中的查询字符串)

1) here user should login with his account so redirect your page here 2) when you came back to your page (Oauth Redirect Page) 3) then take code and state from url(QueryString) 4) send to server (page load event) 5) write following code page_load event(first get query string in code variable)

 OAuth2Parameters parameters = new OAuth2Parameters()
            {
                ClientId = "274488228041-1aaq8a069h3c7lsjstsl394725tumdlo.apps.googleusercontent.com",
                ClientSecret = "Ew1EMwe4EB8oLHvKFfDZxQhp",
                RedirectUri = currentURL,//"http://localhost:6600/Home.html"
                Scope = "https://docs.google.com/feeds/ ",
                State = "documents",
                AccessType = "offline",   // offline means it creats a refreshtoken 
                TokenExpiry = DateTime.Now.AddYears(1)
            };
            parameters.AccessCode = code;

            Google.GData.Client.OAuthUtil.GetAccessToken(parameters);

1),在这里,你会得到accesstoken和requesttoken 2)保存在数据库中供日后用途(离线访问) 3)传递参数来访问谷歌驱动器文件

1) here you will get accesstoken and requesttoken 2) save it in Database for future purpose(offline access) 3) pass parameters to access Google Drive Documents

   GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, "Infactum", parameters);
            DocumentsService service = new DocumentsService("Infactum");
            service.RequestFactory = requestFactory;
            //requestFactory.CustomHeaders["Authorization"] = "Bearer " + parameters.AccessToken;
            DocumentsListQuery query = new DocumentsListQuery();
            query.NumberToRetrieve = 2000;

            // Make a request to the API and get all documents.
            DocumentsFeed feed = service.Query(query);

在这里,你会得到所有类型的饲料对象,你可以访问使用feed.entries文件2000文件...希望你喜欢它

here, You will get all types of 2000 files in feed object you can access files using feed.entries... hope you like it

这篇关于使用.NET谷歌驱动器脱机访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆