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

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

    <bdo id='fveAh'></bdo><ul id='fveAh'></ul>

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

    <legend id='fveAh'><style id='fveAh'><dir id='fveAh'><q id='fveAh'></q></dir></style></legend>
      <tfoot id='fveAh'></tfoot>

        php 中使用 curl 的 OAuth 2.0

        OAuth 2.0 in php using curl(php 中使用 curl 的 OAuth 2.0)
            <i id='SbPtT'><tr id='SbPtT'><dt id='SbPtT'><q id='SbPtT'><span id='SbPtT'><b id='SbPtT'><form id='SbPtT'><ins id='SbPtT'></ins><ul id='SbPtT'></ul><sub id='SbPtT'></sub></form><legend id='SbPtT'></legend><bdo id='SbPtT'><pre id='SbPtT'><center id='SbPtT'></center></pre></bdo></b><th id='SbPtT'></th></span></q></dt></tr></i><div class="5vjrxrd" id='SbPtT'><tfoot id='SbPtT'></tfoot><dl id='SbPtT'><fieldset id='SbPtT'></fieldset></dl></div>
              <tbody id='SbPtT'></tbody>

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

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

                  <legend id='SbPtT'><style id='SbPtT'><dir id='SbPtT'><q id='SbPtT'></q></dir></style></legend>
                  本文介紹了php 中使用 curl 的 OAuth 2.0的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我需要獲取用于 OAuth 2.0 的 access_token 和 refresh_token 才能訪問 Google API,下面的 php 腳本應該返回一個帶有 access_token、refresh_token 的 json,如下所示:

                  I need to get my access_token and refresh_token for OAuth 2.0 to Access Google APIs, the php script below should return a json with access_token, refresh_token like this:

                  {
                    "access_token" : "####",
                    "token_type" : "Bearer",
                    "expires_in" : 3600,
                    "refresh_token" : "####"
                  }
                  

                  但是,php 腳本只返回這個錯誤信息:

                  but, the php script return me only this error message:

                  {
                  "error" : "invalid_request",
                  "error_description" : "Client must specify either client_id or client_assertion, not both"
                  }
                  

                  我嘗試刪除 client_secret/client_id 并僅使用 client_id/client_secret,但仍然出現相同的錯誤.

                  I tried to remove client_secret/client_id and use only client_id/client_secret, but still get the same error.

                  $client_id = '###.apps.googleusercontent.com';
                  $redirect_uri = 'http://localhost/phpConnectToDB/csv/refreshFusionTable.php';
                  $client_secret = '###';
                  
                  $ch = curl_init();
                  
                  curl_setopt($ch, CURLOPT_URL, "https://accounts.google.com/o/oauth2/token");
                  
                  $code = $_REQUEST['code'];
                  
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                  
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                  
                  
                  curl_setopt($ch, CURLOPT_POSTFIELDS, array(
                  'code' => $code,
                  'client_id' => $clientID,
                  'client_secret' => $clientSecret,
                  'redirect_uri' => $redirect_uri,
                  'grant_type' => 'authorization_code'
                  ));
                  
                  $data = curl_exec($ch);
                  
                  var_dump($data);
                  

                  盡管 cmd 中的 curl 可以正常工作并返回我的訪問權限和刷新令牌而沒有任何錯誤.

                  Although curl in cmd works and returns me access and refresh token without any errors.

                  curl --data "code=###&client_id=###.apps.googleusercontent.com&client_secret=###&redirect_uri=http://localhost/phpConnectToDB/csv/refreshFusionTable.php&grant_type=authorization_code" https://accounts.google.com/o/oauth2/token
                  

                  我不明白為什么會出現缺少的方案錯誤,盡管 .php 腳本存在并且它位于給定的路徑上.你能幫我嗎?

                  I don't understand why I get the missing scheme error, although the .php script exists and it's located on the given path. Could you help me please ?

                  EDIT

                  解決了redirect_uri 的參數值無效:缺少方案"的問題,我只是用這個 'redirect_uri' => $redirect_uri 替換了 'redirect_uri' => urlencode($redirect_uri),在CURLOPT_POSTFIELDS.

                  EDIT

                  Problem with "Invalid parameter value for redirect_uri: Missing scheme" solved, I just replaced 'redirect_uri' => urlencode($redirect_uri), with this 'redirect_uri' => $redirect_uri, in CURLOPT_POSTFIELDS.

                  推薦答案

                  哇,愚蠢的錯誤,我應該休息一下.

                  Wow, stupid mistake, I should have a rest.

                  變量名稱不匹配.我定義:

                  The variables names don't match. I defined:

                      $client_id = '###.apps.googleusercontent.com';
                      $client_secret = '###';
                  

                  但是這里我使用了一個不存在的 clientID 和 clientSecret :

                  But here I used an non-existing clientID and clientSecret :

                      curl_setopt($ch, CURLOPT_POSTFIELDS, array(
                      'code' => $code,
                      'client_id' => $clientID,
                      'client_secret' => $clientSecret,
                      'redirect_uri' => $redirect_uri,
                      'grant_type' => 'authorization_code'
                      ));
                  

                  固定和工作的 PHP 腳本

                      $client_id = '###.apps.googleusercontent.com';
                      $redirect_uri = 'http://localhost/phpConnectToDB/csv/refreshFusionTable.php';
                      $client_secret = '###';
                  
                      $ch = curl_init();
                      
                      curl_setopt($ch, CURLOPT_URL, "https://accounts.google.com/o/oauth2/token");
                      
                      curl_setopt($ch, CURLOPT_POST, TRUE);
                      
                      $code = $_REQUEST['code'];
                  
                      // This option is set to TRUE so that the response
                      // doesnot get printed and is stored directly in
                      // the variable
                      curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                      
                      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                      
                      curl_setopt($ch, CURLOPT_POSTFIELDS, array(
                      'code' => $code,
                      'client_id' => $client_id,
                      'client_secret' => $client_secret,
                      'redirect_uri' => $redirect_uri,
                      'grant_type' => 'authorization_code'
                      ));
                  
                      $data = curl_exec($ch);
                      
                      var_dump($data);
                  

                  但是我不得不說google在這里提供了一個有點誤導性的錯誤信息,因為我沒有定義client_id和client_secret,錯誤信息是:

                  But I have to say that google provides a little misleading error message here, because I hadn't defined client_id nor client_secret and the error message was:

                      {
                      "error" : "invalid_request",
                      "error_description" : "Client must specify either client_id or client_assertion, not both"
                      }
                  

                  這篇關于php 中使用 curl 的 OAuth 2.0的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 找不到驅動程序)
                  <i id='SJWfR'><tr id='SJWfR'><dt id='SJWfR'><q id='SJWfR'><span id='SJWfR'><b id='SJWfR'><form id='SJWfR'><ins id='SJWfR'></ins><ul id='SJWfR'></ul><sub id='SJWfR'></sub></form><legend id='SJWfR'></legend><bdo id='SJWfR'><pre id='SJWfR'><center id='SJWfR'></center></pre></bdo></b><th id='SJWfR'></th></span></q></dt></tr></i><div class="hlrbnjn" id='SJWfR'><tfoot id='SJWfR'></tfoot><dl id='SJWfR'><fieldset id='SJWfR'></fieldset></dl></div>

                        • <small id='SJWfR'></small><noframes id='SJWfR'>

                            <tbody id='SJWfR'></tbody>
                          <tfoot id='SJWfR'></tfoot>
                            <bdo id='SJWfR'></bdo><ul id='SJWfR'></ul>

                          • <legend id='SJWfR'><style id='SJWfR'><dir id='SJWfR'><q id='SJWfR'></q></dir></style></legend>
                          • 主站蜘蛛池模板: 广东西屋电气有限公司-广东西屋电气有限公司 | 培训一点通 - 合肥驾校 - 合肥新亚驾校 - 合肥八一驾校 | 细石混凝土泵_厂家_价格-烟台九达机械有限公司 | 南汇8424西瓜_南汇玉菇甜瓜-南汇水蜜桃价格 | 口信网(kousing.com) - 行业资讯_行业展会_行业培训_行业资料 | 超声骨密度仪-骨密度检测仪-经颅多普勒-tcd仪_南京科进实业有限公司 | 山东聚盛新型材料有限公司-纳米防腐隔热彩铝板和纳米防腐隔热板以及钛锡板、PVDF氟膜板供应商 | 周口风机|周风风机|河南省周口通用风机厂| 烟台螺纹,烟台H型钢,烟台钢材,烟台角钢-烟台市正丰金属材料有限公司 | 成都软件开发_OA|ERP|CRM|管理系统定制开发_成都码邻蜀科技 | 郑州宣传片拍摄-TVC广告片拍摄-微电影短视频制作-河南优柿文化传媒有限公司 | 冻干机(冷冻干燥机)_小型|实验型|食品真空冷冻干燥机-松源 | 新能源汽车电机定转子合装机 - 电机维修设备 - 睿望达 | 茅茅虫AI论文写作助手-免费AIGC论文查重_写毕业论文降重 | 沟盖板_复合沟盖板厂_电力盖板_树脂雨水篦子-淄博拜斯特 | 厂房出租_厂房出售_产业园区招商_工业地产&nbsp;-&nbsp;中工招商网 | 下水道疏通_管道疏通_马桶疏通_附近疏通电话- 立刻通 | 2-羟基泽兰内酯-乙酰蒲公英萜醇-甘草查尔酮A-上海纯优生物科技有限公司 | 微妙网,专业的动画师、特效师、CG模型设计师网站! - wmiao.com 超声波电磁流量计-液位计-孔板流量计-料位计-江苏信仪自动化仪表有限公司 | 恒温恒湿试验箱_高低温试验箱_恒温恒湿箱-东莞市高天试验设备有限公司 | 健身器材-健身器材厂家专卖-上海七诚健身器材有限公司 | 台湾阳明固态继电器-奥托尼克斯光电传感器-接近开关-温控器-光纤传感器-编码器一级代理商江苏用之宜电气 | 壹作文_中小学生优秀满分作文大全 | 电动葫芦|防爆钢丝绳电动葫芦|手拉葫芦-保定大力起重葫芦有限公司 | EDLC超级法拉电容器_LIC锂离子超级电容_超级电容模组_软包单体电容电池_轴向薄膜电力电容器_深圳佳名兴电容有限公司_JMX专注中高端品牌电容生产厂家 | 珠光砂保温板-一体化保温板-有釉面发泡陶瓷保温板-杭州一体化建筑材料 | 外观设计_设备外观设计_外观设计公司_产品外观设计_机械设备外观设计_东莞工业设计公司-意品深蓝 | 绿萝净除甲醛|深圳除甲醛公司|测甲醛怎么收费|培训机构|电影院|办公室|车内|室内除甲醛案例|原理|方法|价格立马咨询 | 自动化改造_智虎机器人_灌装机_贴标机-上海圣起包装机械 | 飞利浦LED体育场灯具-吸顶式油站灯-飞利浦LED罩棚灯-佛山嘉耀照明有限公司 | 国产液相色谱仪-超高效液相色谱仪厂家-上海伍丰科学仪器有限公司 | 直流大电流电源,燃料电池检漏设备-上海政飞 | TPE塑胶原料-PPA|杜邦pom工程塑料、PPSU|PCTG材料、PC/PBT价格-悦诚塑胶 | 电子万能试验机_液压拉力试验机_冲击疲劳试验机_材料试验机厂家-济南众标仪器设备有限公司 | 安徽净化板_合肥岩棉板厂家_玻镁板厂家_安徽科艺美洁净科技有限公司 | 沈阳真空机_沈阳真空包装机_沈阳大米真空包装机-沈阳海鹞真空包装机械有限公司 | 免费个人pos机申请办理-移动pos机刷卡-聚合收款码办理 | 九爱图纸|机械CAD图纸下载交流中心 | 广东成考网-广东成人高考网 | 盐水蒸发器,水洗盐设备,冷凝结晶切片机,转鼓切片机,絮凝剂加药系统-无锡瑞司恩机械有限公司 | 大型低温冷却液循环泵-低温水槽冷阱「厂家品牌」京华仪器_京华仪器 |