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

    1. <small id='C3a63'></small><noframes id='C3a63'>

    2. <legend id='C3a63'><style id='C3a63'><dir id='C3a63'><q id='C3a63'></q></dir></style></legend>

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

        <tfoot id='C3a63'></tfoot>

        使用 OAuth Refresh Token 獲取新的 Access Token - Google

        Use OAuth Refresh Token to Obtain New Access Token - Google API(使用 OAuth Refresh Token 獲取新的 Access Token - Google API)
          <tbody id='WbrPM'></tbody>

      2. <legend id='WbrPM'><style id='WbrPM'><dir id='WbrPM'><q id='WbrPM'></q></dir></style></legend>

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

              <i id='WbrPM'><tr id='WbrPM'><dt id='WbrPM'><q id='WbrPM'><span id='WbrPM'><b id='WbrPM'><form id='WbrPM'><ins id='WbrPM'></ins><ul id='WbrPM'></ul><sub id='WbrPM'></sub></form><legend id='WbrPM'></legend><bdo id='WbrPM'><pre id='WbrPM'><center id='WbrPM'></center></pre></bdo></b><th id='WbrPM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='WbrPM'><tfoot id='WbrPM'></tfoot><dl id='WbrPM'><fieldset id='WbrPM'></fieldset></dl></div>
                <tfoot id='WbrPM'></tfoot>
                • <bdo id='WbrPM'></bdo><ul id='WbrPM'></ul>
                • 本文介紹了使用 OAuth Refresh Token 獲取新的 Access Token - Google API的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我的應(yīng)用很簡單,它連接到 Google+ API 對用戶進行身份驗證,如果成功,它會檢索用戶的電子郵件,然后根據(jù)電子郵件對給定的數(shù)據(jù)庫執(zhí)行一系列操作取回.

                  My app is simple, it connects to the Google+ API to authenticate the user, and if successful, it retrieves the user's email and then performs a series of operations on a given database based on the email retrieved.

                  我的主要問題是,我的訪問令牌每小時都會過期,而我似乎不知道如何刷新"它.我收到以下錯誤,我認(rèn)為這是預(yù)期的:

                  My main issue is that every hour, my access token expires, and I seem not to know how to "refresh" it. I get the following error, which I imagine is expected:

                  The OAuth 2.0 access token has expired, and a refresh token is not available.
                  

                  我目前正在將訪問令牌存儲在數(shù)據(jù)庫中,因此我可以根據(jù)需要進行檢索.我唯一的問題是如何使用該令牌來獲得新令牌?

                  I am currently storing the access token on a database, and I can therefore retrieve if needed. My only question is how do I use that token to gain a new one?

                  推薦答案

                  哇,我花了很長時間才弄明白這個問題,而且這些答案對我來說似乎很不完整.

                  Whoa, it took me significantly longer to figure this out, and the answers out there seemed quite incomplete to me.

                  在我們開始之前請記住,這個答案假設(shè)您使用的是最新的 Google APIPHP 庫,截至 2014 年 5 月 26 日.

                  Before we start please keep in mind that this answer assumes you are using the latest Google API PHP Library, as of May 26th of 2014.

                  1 - 確保您的應(yīng)用請求的訪問類型是offline.refresh_token 否則不提供.來自 Google:此字段僅在授權(quán)代碼請求中包含 access_type=offline 時才存在.

                  1 - Make sure the access type your app requests is offline. A refresh_token is not provided otherwise. From Google: This field is only present if access_type=offline is included in the authorization code request.

                  $gClient->setAccessType('offline');
                  

                  2 - 在第一次授權(quán)時,保留提供的 refresh_token 以供進一步訪問.這可以通過cookies數(shù)據(jù)庫等來完成.我選擇存儲在數(shù)據(jù)庫中:

                  2 - Upon the first authorization, persist the provided refresh_token for further access. This can be done via cookies, database, etc. I chose to store in on a database:

                  $tokens = json_decode($gClient->getAccessToken()); /* Get a JSON object */
                  setRefreshToken($con, $tokens->refresh_token /* Retrieve form JSON object */);
                  

                  3 - 檢查 AccessToken 是否已過期,如果是這種情況,請從 Google 請求刷新的令牌.

                  3 - Check if the AccessToken has expired, and request a refreshed token from Google if such is the case.

                  if ($gClient->isAccessTokenExpired()) {    
                    $refreshToken = getRefreshToken($con, $email); 
                    $gClient->refreshToken($refreshToken);
                  }  
                  

                  其中 getRefreshToken 是從我們的數(shù)據(jù)庫中檢索先前存儲的 refresh_token,然后我們將該值傳遞給客戶端的 refreshToken 方法.

                  Where getRefreshToken is retrieving the previously stored refresh_token from our database, and then we pass that value to the Client's refreshToken method.

                  快速說明:重要的是要記住,如果您之前已授權(quán)您的應(yīng)用程序,您可能不會在響應(yīng)中看到 refresh_token,因為它僅提供我們第一次調(diào)用authenticate.因此,您可以轉(zhuǎn)到 https://www.google.com/settings/security 和撤消對您的應(yīng)用的訪問權(quán)限,或者您可以在創(chuàng)建客戶端對象時添加以下行:

                  Quick Note: It's key to remember that if you had previously authorized your app, you probably won't see a refresh_token on the response, since it is only provided the first time we call authenticate. Therefore, you can either go to https://www.google.com/settings/security and Revoke Access to your app or you can add the following line when creating the Client object:

                  $gClient->setApprovalPrompt('force');
                  

                  來自 Google:如果值為 force,則用戶會看到一個同意頁面,即使他們之前就給定的一組范圍同意了您的應(yīng)用程序.這反過來又確保了 refresh_token 在每次授權(quán)中提供.

                  From Google: If the value is force, then the user sees a consent page even if they previously gave consent to your application for a given set of scopes. Which in turn ensures that a refresh_token is provided on each authorization.

                  完整示例:http://pastebin.com/jA9sBNTk

                  這篇關(guān)于使用 OAuth Refresh Token 獲取新的 Access Token - Google API的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標(biāo)不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動程序)

                    <tfoot id='DxWLF'></tfoot>

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

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

                          <tbody id='DxWLF'></tbody>
                            <legend id='DxWLF'><style id='DxWLF'><dir id='DxWLF'><q id='DxWLF'></q></dir></style></legend>
                          • 主站蜘蛛池模板: 国产91精品久久久久久久网曝门 | 一区二区三区视频在线观看 | 国产欧美精品 | 久久久久免费观看 | 国产在线一区二区 | 国产精品久久国产精品 | 精品在线观看入口 | 国产精品揄拍一区二区久久国内亚洲精 | 91精品国产91久久久久久最新 | 久久综合一区 | 国产亚洲精品91 | 国产精品99久久久久久久vr | 激情久久网| 羞羞视频在线观看 | 亚洲婷婷六月天 | 欧美自拍日韩 | 免费看av大片 | 91成人免费 | 超碰免费在线观看 | 一级免费看片 | 国产美女精品视频免费观看 | 欧美精品久久久 | 久久久91精品国产一区二区三区 | 在线视频h | 久久综合香蕉 | 国产欧美精品区一区二区三区 | 久久亚洲欧美日韩精品专区 | 亚洲美乳中文字幕 | 欧美三级视频在线观看 | 午夜欧美一区二区三区在线播放 | 亚洲视频在线一区 | 中文字幕成人网 | 免费久草 | 天堂久久天堂综合色 | 国产在线小视频 | 国产成人精品视频在线观看 | 日韩午夜网站 | 亚洲精品日日夜夜 | 台湾佬久久 | 99久久精品国产毛片 | av国产精品毛片一区二区小说 |