pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

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

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

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

        <legend id='QBYVN'><style id='QBYVN'><dir id='QBYVN'><q id='QBYVN'></q></dir></style></legend>
      1. 服務應用程序和 Google Analytics API V3:服務器到服務

        Service Applications and Google Analytics API V3: Server-to-server OAuth2 authentication?(服務應用程序和 Google Analytics API V3:服務器到服務器 OAuth2 身份驗證?)
      2. <small id='2g00C'></small><noframes id='2g00C'>

        • <legend id='2g00C'><style id='2g00C'><dir id='2g00C'><q id='2g00C'></q></dir></style></legend>

                <bdo id='2g00C'></bdo><ul id='2g00C'></ul>
                    <tbody id='2g00C'></tbody>

                  <i id='2g00C'><tr id='2g00C'><dt id='2g00C'><q id='2g00C'><span id='2g00C'><b id='2g00C'><form id='2g00C'><ins id='2g00C'></ins><ul id='2g00C'></ul><sub id='2g00C'></sub></form><legend id='2g00C'></legend><bdo id='2g00C'><pre id='2g00C'><center id='2g00C'></center></pre></bdo></b><th id='2g00C'></th></span></q></dt></tr></i><div class="5hvn7bb" id='2g00C'><tfoot id='2g00C'></tfoot><dl id='2g00C'><fieldset id='2g00C'></fieldset></dl></div>
                  <tfoot id='2g00C'></tfoot>
                1. 本文介紹了服務應用程序和 Google Analytics API V3:服務器到服務器 OAuth2 身份驗證?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試制作一個服務器應用程序,以便定期從我自己的 GA 帳戶中提取 Google Analytics(分析)數據.請注意,它是訪問我自己數據的個人服務器端應用程序,即沒有最終用戶訪問此應用程序.

                  I'm trying to make a server application to routinely pull Google Analytics data from my own GA account. Note, it is a personal, server-side application accessing my own data, i.e. there is no end-user accessing this application.

                  因此,我在 Google API 控制臺 中將我的應用程序注冊為服務應用程序,它給了我一個客戶 ID 和一個私鑰.我的理解是,服務應用程序不使用應用程序機密重定向 URL,因為在此服務器到服務器身份驗證流程中沒有最終用戶.事實上,Google API 控制臺沒有給我任何秘密,也沒有提示我輸入重定向 URL.

                  As such, I registered my application in the Google API Console as a Service Application, which gave me a Client ID and a Private Key. It is my understanding that Service Applications do NOT use Application Secret and Redirect URL as there is no end-user in this server-to-server authentication flow. Indeed, the Google API Console gave me no Secret and did not prompt me for a Redirect URL.

                  不幸的是,我無法弄清楚如何在 Google 的內部驗證我的服務應用程序PHP 客戶端 API.有大量關于向最終用戶驗證 Web 應用程序的文檔.

                  Unfortunately, I can not figure out how to authenticate my Service Application within Google's PHP Client API. There is extensive documentation on authenticating web applications with an end-user.

                  Google 的文檔建議 可以通過使用私鑰.我只是不知道如何在 PHP 客戶端 API 中執行(盡管我已經瀏覽了源代碼并且有 絕對是一個用私鑰簽署請求的腳本.)

                  Google's documentation suggests it is possible to authenticate server-to-server by signing a JWT request with the private key. I just can't figure out how to do within the PHP client API (although I've browsed the source and there's definitely a script that signs a request with the private key.)

                  我在這里遺漏了什么嗎?如何使用我的私鑰和 Google PHP 客戶端 API 對服務應用程序執行身份驗證?

                  Am I missing something here? How can I perform authentication for a Service Application with my private key and the Google PHP client API?

                  為清晰起見進行了編輯

                  推薦答案

                  2012 年 7 月 21 日更新

                  Google Analytics API V3 現在支持由 .p12 簽名的 JWT 請求返回的 OAuth2 令牌.也就是說,我們現在可以使用帶有服務帳戶的 Analytics API.

                  目前正在提取 4 年的逐日指標,只是為了它.

                  Currently pulling 4 years of day-by-day metrics, just for the hell of it.

                  這是一個快速的n"步驟:

                  Here's a quick 'n' dirty step-by-step:

                  1. 轉到 Google API 控制臺并創建一個新應用

                  服務標簽中,打開Google Analytics開關

                  API 訪問選項卡中,點擊創建 OAuth2.0 客戶端 ID

                  • 輸入您的姓名,上傳徽標,然后單擊下一步

                  選擇服務帳戶選項,然后按創建客戶 ID

                  下載您的私鑰

                  現在您又回到了API 訪問頁面.您將看到一個名為服務帳戶的部分,其中包含一個客戶 ID電子郵件地址

                  Now you're back on the API Access page. You'll see a section called Service account with a Client ID and Email address

                  • 復制電子郵件地址(類似于####@developer.gserviceaccount.com)

                  訪問您的GA管理員并將此電子郵件添加為用戶到您的屬性

                  這是必須的;否則你會得到神秘的錯誤.

                  This is a must; you'll get cryptic errors otherwise.

                  通過 Github 獲取最新的 Google PHP 客戶端 API

                  Get the latest Google PHP Client API via Github

                  git submodule add https://github.com/google/google-api-php-client.git google-api-php-client-read-only
                  

                2. 搖滾樂(感謝大家提供有關更新類名稱的提示):

                3. Rock 'n' roll (thanks all for tips on updated class names):

                  // api dependencies
                  require_once(PATH_TO_API . 'Google/Client.php');
                  require_once(PATH_TO_API . 'Google/Service/Analytics.php');
                  
                  // create client object and set app name
                  $client = new Google_Client();
                  $client->setApplicationName(APP_NAME); // name of your app
                  
                  // set assertion credentials
                  $client->setAssertionCredentials(
                    new Google_Auth_AssertionCredentials(
                  
                      APP_EMAIL, // email you added to GA
                  
                      array('https://www.googleapis.com/auth/analytics.readonly'),
                  
                      file_get_contents(PATH_TO_PRIVATE_KEY_FILE)  // keyfile you downloaded
                  
                  ));
                  
                  // other settings
                  $client->setClientId(CLIENT_ID);           // from API console
                  $client->setAccessType('offline_access');  // this may be unnecessary?
                  
                  // create service and get data
                  $service = new Google_Service_Analytics($client);
                  $service->data_ga->get($ids, $startDate, $endDate, $metrics, $optParams);
                  

                4.  

                  下面的原始解決方法

                  似乎,盡管文檔含糊不清,大多數 Google API 都可以尚不支持服務帳戶,包括 Google Analytics.他們無法消化 .p12 簽名的 JWT 請求返回的 OAuth2 令牌.所以,就目前而言,您不能將 Google Analytics API V3 與服務帳號.

                  It seems that, despite ambiguous documentation, most Google APIs do not support service accounts yet, including Google Analytics. They cannot digest OAuth2 tokens returned by a .p12 signed JWT request. So, as of right now, you cannot use Google Analytics API V3 with a service account.

                  解決方法:

                  1. 在 Google API 控制臺中,創建一個 客戶端應用程序.

                  1. In the Google API console, create a client application.

                  按照 Google PHP Client API 示例中的步驟生成client_auth_url 使用您的 client_idclient_secret、和 redirect_uri

                  Follow the steps in the Google PHP Client API examples to generate a client_auth_url using your client_id, client_secret, and redirect_uri

                  使用 cURL 登錄 Google.(一定要使用cookie文件!)

                  Login to Google using cURL. (Be sure to use a cookie file!)

                  在 cURL 中打開 client_auth_url 并完成表單.確保你設置了 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);curl_setopt($ch, CURLOPT_HEADER, 1); 作為authorization_code將位于響應的 Location: 標頭中.

                  Open the client_auth_url in cURL and complete the form. Make sure you set curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); and curl_setopt($ch, CURLOPT_HEADER, 1); as the authorization_code will be in the Location: header of the response.

                  使用您的 client_id、client_secret、redirect_uri 和第 4 步中的激活碼,向 Google 的 OAuth2令牌機.確保包含 grant_type =authorization_code" 在您的帖子字段中.

                  Using your client_id, client_secret, redirect_uri, and the activation code from Step 4, post a request to the Google's OAuth2 Token machine. Make sure you include grant_type = "authorization_code" in your post fields.

                  萬歲,您現在擁有一個永不過期的 refresh_token 和一個有效的 access_token!向 Google 的 OAuth2 令牌發布請求機器和你的client_id、client_secret、redirect_uri,和 refresh_token 當您的 access_token 到期時,您將獲得新的.

                  Hurray, you now have a refresh_token that never expires, and a working access_token! Post a request to the Google's OAuth2 Token machine with your client_id, client_secret, redirect_uri, and refresh_token when your access_token expires and you'll get a new one.

                  這篇關于服務應用程序和 Google Analytics API V3:服務器到服務器 OAuth2 身份驗證?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

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

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

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

                            <tbody id='renD1'></tbody>

                            <legend id='renD1'><style id='renD1'><dir id='renD1'><q id='renD1'></q></dir></style></legend>
                          1. 主站蜘蛛池模板: 安徽净化板_合肥岩棉板厂家_玻镁板厂家_安徽科艺美洁净科技有限公司 | 泰州物流公司_泰州货运公司_泰州物流专线-东鑫物流公司 | 济南品牌包装设计公司_济南VI标志设计公司_山东锐尚文化传播 | 外贮压-柜式-悬挂式-七氟丙烷-灭火器-灭火系统-药剂-价格-厂家-IG541-混合气体-贮压-非贮压-超细干粉-自动-灭火装置-气体灭火设备-探火管灭火厂家-东莞汇建消防科技有限公司 | 胶辊硫化罐_胶鞋硫化罐_硫化罐厂家-山东鑫泰鑫智能装备有限公司 意大利Frascold/富士豪压缩机_富士豪半封闭压缩机_富士豪活塞压缩机_富士豪螺杆压缩机 | 哈希余氯测定仪,分光光度计,ph在线监测仪,浊度测定仪,试剂-上海京灿精密机械有限公司 | 安徽成考网-安徽成人高考网 | 建筑消防设施检测系统检测箱-电梯**检测仪器箱-北京宇成伟业科技有限责任公司 | 气动机械手-搬运机械手-气动助力机械手-山东精瑞自动化设备有限公司 | 整车VOC采样环境舱-甲醛VOC预处理舱-多舱法VOC检测环境仓-上海科绿特科技仪器有限公司 | 烘箱-工业烘箱-工业电炉-实验室干燥箱 - 苏州华洁烘箱制造有限公司 | 线粒体膜电位荧光探针-细胞膜-标记二抗-上海复申生物科技有限公司 | 健康管理师报考条件,考试时间,报名入口—首页 | 利浦顿蒸汽发生器厂家-电蒸汽发生器/燃气蒸汽发生器_湖北利浦顿热能科技有限公司官网 | 可程式恒温恒湿试验箱|恒温恒湿箱|恒温恒湿试验箱|恒温恒湿老化试验箱|高低温试验箱价格报价-广东德瑞检测设备有限公司 | 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库 | 慢回弹测试仪-落球回弹测试仪-北京冠测精电仪器设备有限公司 | 粉丝机械,粉丝烘干机,粉丝生产线-招远市远东粉丝机械有限公司 | 电镀标牌_电铸标牌_金属标贴_不锈钢标牌厂家_深圳市宝利丰精密科技有限公司 | 变压器配件,变压器吸湿器,武强县吉口变压器配件有限公司 | 恒温油槽-恒温水槽-低温恒温槽厂家-宁波科麦仪器有限公司 | 苏商学院官网 - 江苏地区唯一一家企业家自办的前瞻型、实操型商学院 | 污水/卧式/潜水/钻井/矿用/大型/小型/泥浆泵,价格,参数,型号,厂家 - 安平县鼎千泵业制造厂 | 能耗监测系统-节能监测系统-能源管理系统-三水智能化 | 钛板_钛管_钛棒_钛盘管-无锡市盛钛科技有限公司 | 小型高低温循环试验箱-可程式高低温湿热交变试验箱-东莞市拓德环境测试设备有限公司 | 高温热泵烘干机,高温烘干热泵,热水设备机组_正旭热泵 | 天津市能谱科技有限公司-专业的红外光谱仪_红外测油仪_紫外测油仪_红外制样附件_傅里叶红外光谱技术生产服务厂商 | 儿童语言障碍训练-武汉优佳加感统文化发展有限公司 | 市政路灯_厂家-淄博信达电力科技有限公司 | 千淘酒店差旅平台-中国第一家针对TMC行业的酒店资源供应平台 | 实验室装修_实验室设计_实验室规划设计- 上海广建净化工程公司 | 凝胶成像系统(wb成像系统)百科-上海嘉鹏 | 私人别墅家庭影院系统_家庭影院音响_家庭影院装修设计公司-邦牛影音 | 洛阳防爆合格证办理-洛阳防爆认证机构-洛阳申请国家防爆合格证-洛阳本安防爆认证代办-洛阳沪南抚防爆电气技术服务有限公司 | 超声波成孔成槽质量检测仪-压浆机-桥梁预应力智能张拉设备-上海硕冠检测设备有限公司 | 电动垃圾车,垃圾清运车-江苏速利达机车有限公司 | 鲁尔圆锥接头多功能测试仪-留置针测试仪-上海威夏环保科技有限公司 | 胶泥瓷砖胶,轻质粉刷石膏,嵌缝石膏厂家,腻子粉批发,永康家德兴,永康市家德兴建材厂 | 广州番禺搬家公司_天河黄埔搬家公司_企业工厂搬迁_日式搬家_广州搬家公司_厚道搬迁搬家公司 | 优考试_免费在线考试系统_培训考试系统_题库系统_组卷答题系统_匡优考试 |