久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <tfoot id='EFbVA'></tfoot>
      <bdo id='EFbVA'></bdo><ul id='EFbVA'></ul>

      <i id='EFbVA'><tr id='EFbVA'><dt id='EFbVA'><q id='EFbVA'><span id='EFbVA'><b id='EFbVA'><form id='EFbVA'><ins id='EFbVA'></ins><ul id='EFbVA'></ul><sub id='EFbVA'></sub></form><legend id='EFbVA'></legend><bdo id='EFbVA'><pre id='EFbVA'><center id='EFbVA'></center></pre></bdo></b><th id='EFbVA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='EFbVA'><tfoot id='EFbVA'></tfoot><dl id='EFbVA'><fieldset id='EFbVA'></fieldset></dl></div>
    1. <legend id='EFbVA'><style id='EFbVA'><dir id='EFbVA'><q id='EFbVA'></q></dir></style></legend>

      <small id='EFbVA'></small><noframes id='EFbVA'>

      MVC 中的 GoogleWebAuthorizationBroker 用于 Google Drive 訪

      GoogleWebAuthorizationBroker in MVC For Google Drive Access(MVC 中的 GoogleWebAuthorizationBroker 用于 Google Drive 訪問(wèn))

    2. <tfoot id='rAKm9'></tfoot>
            • <bdo id='rAKm9'></bdo><ul id='rAKm9'></ul>

                <tbody id='rAKm9'></tbody>
            • <legend id='rAKm9'><style id='rAKm9'><dir id='rAKm9'><q id='rAKm9'></q></dir></style></legend>
            • <small id='rAKm9'></small><noframes id='rAKm9'>

              <i id='rAKm9'><tr id='rAKm9'><dt id='rAKm9'><q id='rAKm9'><span id='rAKm9'><b id='rAKm9'><form id='rAKm9'><ins id='rAKm9'></ins><ul id='rAKm9'></ul><sub id='rAKm9'></sub></form><legend id='rAKm9'></legend><bdo id='rAKm9'><pre id='rAKm9'><center id='rAKm9'></center></pre></bdo></b><th id='rAKm9'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='rAKm9'><tfoot id='rAKm9'></tfoot><dl id='rAKm9'><fieldset id='rAKm9'></fieldset></dl></div>

                本文介紹了MVC 中的 GoogleWebAuthorizationBroker 用于 Google Drive 訪問(wèn)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                問(wèn)題描述

                我無(wú)法從 MVC 應(yīng)用程序訪問(wèn)特定的 Google Drive 帳戶.我所需要的只是讓 MVC Web 應(yīng)用程序訪問(wèn)我的谷歌驅(qū)動(dòng)器掃描幾個(gè)文件并根據(jù)谷歌驅(qū)動(dòng)器的內(nèi)容更改數(shù)據(jù)庫(kù).問(wèn)題是在 IIS 中運(yùn)行時(shí),驅(qū)動(dòng)器無(wú)法通過(guò)身份驗(yàn)證,因?yàn)槿绻?GoogleWebAuthorizationBroker 嘗試打開瀏覽器(如果它是 Windows 應(yīng)用程序)但似乎無(wú)法通過(guò) IIS 執(zhí)行此操作,即使它是服務(wù)器端的.

                I'm stuck trying to access a specific Google drive account from a MVC app. All I need is for the MVC web app to access my google drive scan for a few files and alter the database based on the contents of the google drive. The problem is when running in IIS the drive cannot be authenticated as GoogleWebAuthorizationBroker tries to open browser if its a windows app but doesn't seem to be able to do that through IIS and even if it did it would be server side.

                理想情況下,我根本不需要對(duì)這個(gè)應(yīng)用程序進(jìn)行身份驗(yàn)證,但如果它確實(shí)通過(guò)了驗(yàn)證,那么我該如何讓它在 IIS 中工作?

                Ideally I would not have to authenticate this app at all, but if it has do go through that then how do I make it work in IIS?

                UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    new ClientSecrets
                            {
                                ClientId = "MY_ID",
                                ClientSecret = "My_Secret"
                            },
                            new[] { DriveService.Scope.Drive },
                            "user",
                            CancellationToken.None, dataStore: new FileDataStore(Server.MapPath("~/app_data/googledata"))).Result;
                

                推薦答案

                我得到了這個(gè)工作,能夠使網(wǎng)站使用我的帳戶訪問(wèn) Google 驅(qū)動(dòng)器,而無(wú)需要求用戶登錄或授權(quán).

                I got this to work, was able to enable the web site to access Google drive using my account without asking users to login or authorize.

                首先,點(diǎn)擊此鏈接讓 Google API 與 MVC 一起工作:

                First of all, follow this link to get Google API work with MVC:

                https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#web_applications

                示例代碼中存在問(wèn)題,在 HomeController 中

                There is a problem in the Sample code, in HomeController

                 public async Task IndexAsync(CancellationToken cancellationToken)
                

                應(yīng)該是:

                 public async Task<ActionResult> IndexAsync(CancellationToken cancellationToken)
                

                之后,我創(chuàng)建了一個(gè) MemoryDataStore(參見最后的代碼),它是對(duì)此處發(fā)布的 MemoryDataStore 的輕微修改:

                After that, I created a MemoryDataStore (see code at the end) that is a slightly modification from the MemoryDataStore posted here:

                http://conficient.wordpress.com/2014/06/18/using-google-drive-api-with-c-part-2/

                完成此操作后,捕獲您正在使用的帳戶的刷新令牌,并在驗(yàn)證時(shí)將存儲(chǔ)替換為此存儲(chǔ):

                Once you do that, capture the refresh token of the account you are using, and replace the store with this store when authenticate:

                    private static readonly IAuthorizationCodeFlow flow =
                        new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
                            {
                                ClientSecrets = new ClientSecrets
                                {
                                    ClientId = clientID,
                                    ClientSecret = clientSecret
                                },
                                Scopes = new[] { DriveService.Scope.Drive },
                                //DataStore = new FileDataStore("Drive.Api.Auth.Store")
                                DataStore = new GDriveMemoryDataStore(commonUser, refreshToken)
                            });
                

                這里的 commonUser 是您選擇的預(yù)定義用戶 ID.請(qǐng)務(wù)必修改 GetUserID() 方法以返回相同的 commonUser:

                Here commonUser is a predefined user id of your chosen. Please make sure to modify the GetUserID() method to return the same commonUser:

                 public override string GetUserId(Controller controller)
                    {
                        return commonUser;
                    }
                

                完成此操作后,Google Drive 將停止要求用戶登錄和授權(quán)應(yīng)用程序.

                Once this is done, Google drive will stop asking user to login and authorize the app.

                這是我的 MemoryDataStore 代碼:

                Here is my MemoryDataStore code:

                 /// <summary>
                 /// Handles internal token storage, bypassing filesystem
                 /// </summary>
                internal class GDriveMemoryDataStore : IDataStore
                 {
                     private Dictionary<string, TokenResponse> _store;
                     private Dictionary<string, string> _stringStore;
                
                     //private key password: notasecret
                
                     public GDriveMemoryDataStore()
                     {
                         _store = new Dictionary<string, TokenResponse>();
                         _stringStore = new Dictionary<string, string>();
                     }
                
                     public GDriveMemoryDataStore(string key, string refreshToken)
                     {
                         if (string.IsNullOrEmpty(key))
                             throw new ArgumentNullException("key");
                         if (string.IsNullOrEmpty(refreshToken))
                             throw new ArgumentNullException("refreshToken");
                
                         _store = new Dictionary<string, TokenResponse>();
                
                         // add new entry
                         StoreAsync<TokenResponse>(key,
                             new TokenResponse() { RefreshToken = refreshToken, TokenType = "Bearer" }).Wait();
                     }
                
                     /// <summary>
                     /// Remove all items
                     /// </summary>
                     /// <returns></returns>
                     public async Task ClearAsync()
                     {
                         await Task.Run(() =>
                         {
                             _store.Clear();
                             _stringStore.Clear();
                         });
                     }
                
                     /// <summary>
                     /// Remove single entry
                     /// </summary>
                     /// <typeparam name="T"></typeparam>
                     /// <param name="key"></param>
                     /// <returns></returns>
                     public async Task DeleteAsync<T>(string key)
                     {
                         await Task.Run(() =>
                         {
                            // check type
                             AssertCorrectType<T>();
                
                             if (typeof(T) == typeof(string))
                             {
                                 if (_stringStore.ContainsKey(key))
                                     _stringStore.Remove(key);                 
                             }
                             else if (_store.ContainsKey(key))
                             {
                                 _store.Remove(key);
                             }
                         });
                     }
                
                     /// <summary>
                     /// Obtain object
                     /// </summary>
                     /// <typeparam name="T"></typeparam>
                     /// <param name="key"></param>
                     /// <returns></returns>
                     public async Task<T> GetAsync<T>(string key)
                     {
                         // check type
                         AssertCorrectType<T>();
                
                         if (typeof(T) == typeof(string))
                         {
                             if (_stringStore.ContainsKey(key))
                                 return await Task.Run(() => { return (T)(object)_stringStore[key]; });
                         }
                         else if (_store.ContainsKey(key))
                         {
                             return await Task.Run(() => { return (T)(object)_store[key]; });
                         }
                         // key not found
                         return default(T);
                     }
                
                     /// <summary>
                     /// Add/update value for key/value
                     /// </summary>
                     /// <typeparam name="T"></typeparam>
                     /// <param name="key"></param>
                     /// <param name="value"></param>
                     /// <returns></returns>
                     public Task StoreAsync<T>(string key, T value)
                     {
                         return Task.Run(() =>
                         {
                             if (typeof(T) == typeof(string))
                             {
                                 if (_stringStore.ContainsKey(key))
                                     _stringStore[key] = (string)(object)value;
                                 else
                                     _stringStore.Add(key, (string)(object)value);
                             } else
                             {
                                 if (_store.ContainsKey(key))
                                     _store[key] = (TokenResponse)(object)value;
                                 else
                                     _store.Add(key, (TokenResponse)(object)value);
                             }
                         });
                     }
                
                     /// <summary>
                     /// Validate we can store this type
                     /// </summary>
                     /// <typeparam name="T"></typeparam>
                     private void AssertCorrectType<T>()
                     {
                         if (typeof(T) != typeof(TokenResponse) && typeof(T) != typeof(string)) 
                             throw new NotImplementedException(typeof(T).ToString());
                     }
                 }
                

                這篇關(guān)于MVC 中的 GoogleWebAuthorizationBroker 用于 Google Drive 訪問(wèn)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                相關(guān)文檔推薦

                Ignore whitespace while reading XML(讀取 XML 時(shí)忽略空格)
                XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)
                Reading XML with unclosed tags in C#(在 C# 中讀取帶有未閉合標(biāo)簽的 XML)
                Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、單元格)
                delete element from xml using LINQ(使用 LINQ 從 xml 中刪除元素)
                Parse malformed XML(解析格式錯(cuò)誤的 XML)
                  <bdo id='eG58L'></bdo><ul id='eG58L'></ul>
                      <tbody id='eG58L'></tbody>
                  • <i id='eG58L'><tr id='eG58L'><dt id='eG58L'><q id='eG58L'><span id='eG58L'><b id='eG58L'><form id='eG58L'><ins id='eG58L'></ins><ul id='eG58L'></ul><sub id='eG58L'></sub></form><legend id='eG58L'></legend><bdo id='eG58L'><pre id='eG58L'><center id='eG58L'></center></pre></bdo></b><th id='eG58L'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='eG58L'><tfoot id='eG58L'></tfoot><dl id='eG58L'><fieldset id='eG58L'></fieldset></dl></div>
                      1. <tfoot id='eG58L'></tfoot>

                        <legend id='eG58L'><style id='eG58L'><dir id='eG58L'><q id='eG58L'></q></dir></style></legend>

                        <small id='eG58L'></small><noframes id='eG58L'>

                        1. 主站蜘蛛池模板: 欧美亚洲国产日韩 | 日韩一级大片 | 中文日韩在线 | 狠狠操狠狠操 | 日韩在线小视频 | 女同一区二区 | 国产精品久久久久久久 | 九九视频在线 | 爱搞逼综合网 | 美女视频一区二区 | 亚洲在线播放 | 久久天堂av | www久久久久| 黄色小视频免费看 | 黄色裸体视频 | 亚洲精品久久久久 | 91在线免费视频观看 | 午夜免费小视频 | 久久亚洲欧美 | 色在线视频 | 欧美777| 天堂а√在线中文在线新版 | 亚洲影院一区 | 国产成人综合视频 | 在线免费观看av网站 | 黄色一级片网站 | 国产精品99久久久久久久久久久久 | 日本色综合 | 欧美一区二区三区在线观看视频 | 能看毛片的网站 | 国产精品欧美激情 | 免费毛片视频 | 国产视频www| 欧美精品色 | 精品蜜桃一区二区三区 | 理论片中文字幕 | 久久久久亚洲精品 | av色婷婷 | 日韩欧美中文在线 | 国产免费一级片 | 亚洲精品在线看 |