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

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

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

        • <bdo id='rkdpf'></bdo><ul id='rkdpf'></ul>

        從 Google OAuth 2.0 PHP API 獲取用戶信息

        Get Userinfo from Google OAuth 2.0 PHP API(從 Google OAuth 2.0 PHP API 獲取用戶信息)
          <tbody id='gPvWs'></tbody>

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

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

        • <legend id='gPvWs'><style id='gPvWs'><dir id='gPvWs'><q id='gPvWs'></q></dir></style></legend>

        • <tfoot id='gPvWs'></tfoot>

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

                  本文介紹了從 Google OAuth 2.0 PHP API 獲取用戶信息的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試使用 Google Oauth API 來獲取用戶信息.它非常適合 Google Plus API,但我正在嘗試創建備份,以防用戶沒有 google plus 帳戶.身份驗證過程是正確的,我什至獲得了 $userinfo 對象,但我究竟如何訪問這些屬性.我試過 $userinfo->get() 但它只返回用戶的 id.

                  我做錯了嗎?這是我正在使用的代碼...

                  require_once '../../src/Google_Client.php';require_once '../../src/contrib/Google_Oauth2Service.php';session_start();$client = new Google_Client();$client->setApplicationName("Google+ PHP Starter Application");//訪問 https://code.google.com/apis/console 生成您的//oauth2_client_id、oauth2_client_secret,并注冊您的 oauth2_redirect_uri.$client->setClientId('*********************');$client->setClientSecret('****************');$client->setRedirectUri('***************');$client->setDeveloperKey('**************');$plus = new Google_Oauth2Service($client);如果(isset($_REQUEST ['注銷'])){未設置($_SESSION['access_token']);}如果(isset($_GET['代碼'])){$client->authenticate($_GET['code']);$_SESSION['access_token'] = $client->getAccessToken();header('位置:http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);}如果(isset($_SESSION['access_token'])){$client->setAccessToken($_SESSION['access_token']);}if ($client->getAccessToken()){$userinfo = $plus->userinfo;print_r($userinfo->get());} 別的{$authUrl = $client->createAuthUrl();}?><!doctype html><頭><meta charset="utf-8"><link rel='stylesheet' href='style.css'/><身體><header><h1>Google+ 示例應用</h1></header><div class="box"><?php if(isset($personMarkup)): ?><div class="me"><?php print $personMarkup ?></div><?php endif ?><?php如果(isset($authUrl)){print "<a class='login' href='$authUrl'>連接我!</a>";} 別的 {打印 "<a class='logout' href='?logout'>Logout</a>";}?>

                  謝謝...

                  **編輯***缺少范圍--已添加

                   $client->setScopes(array('https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile'));

                  現在工作...

                  解決方案

                  缺少作用域

                  $client->setScopes(array('https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile'));

                  現在就像一個魅力!

                  I am trying to use Google Oauth API to get userinfo. It works perfectly for Google Plus API but I am trying to create a backup in case the user doesn't have google plus account. The authentication process is correct and I even get the $userinfo object but how exactly do I access the properties. I tried $userinfo->get() but it only return the id of the user.

                  Am I doing something wrong? Here is the code that I am using...

                  require_once '../../src/Google_Client.php';
                  require_once '../../src/contrib/Google_Oauth2Service.php';
                  
                  session_start();
                  
                  $client = new Google_Client();
                  $client->setApplicationName("Google+ PHP Starter Application");
                  // Visit https://code.google.com/apis/console to generate your
                  // oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri.
                   $client->setClientId('*********************');
                   $client->setClientSecret('**************');
                   $client->setRedirectUri('***************');
                   $client->setDeveloperKey('**************');
                  $plus = new Google_Oauth2Service($client);
                  
                  if (isset($_REQUEST['logout'])) {
                    unset($_SESSION['access_token']);
                  }
                  
                  if (isset($_GET['code'])) {
                    $client->authenticate($_GET['code']);
                    $_SESSION['access_token'] = $client->getAccessToken();
                    header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
                  }
                  
                  if (isset($_SESSION['access_token'])) {
                    $client->setAccessToken($_SESSION['access_token']);
                  }
                  
                  if ($client->getAccessToken()) 
                  {
                      $userinfo = $plus->userinfo;
                      print_r($userinfo->get());
                  
                  } else 
                  {
                      $authUrl = $client->createAuthUrl();
                  }
                  ?>
                  <!doctype html>
                  <html>
                  <head>
                    <meta charset="utf-8">
                    <link rel='stylesheet' href='style.css' />
                  </head>
                  <body>
                  <header><h1>Google+ Sample App</h1></header>
                  <div class="box">
                  
                  <?php if(isset($personMarkup)): ?>
                  <div class="me"><?php print $personMarkup ?></div>
                  <?php endif ?>
                  
                  <?php
                    if(isset($authUrl)) {
                      print "<a class='login' href='$authUrl'>Connect Me!</a>";
                    } else {
                     print "<a class='logout' href='?logout'>Logout</a>";
                    }
                  ?>
                  </div>
                  </body>
                  </html>
                  

                  Thanks...

                  **EDIT*** Was missing Scopes--Added

                   $client->setScopes(array('https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile'));
                  

                  works now...

                  解決方案

                  Was missing scopes

                  $client->setScopes(array('https://www.googleapis.com/auth/userinfo.email','https://www.googleapis.com/auth/userinfo.profile'));
                  

                  Works like a charm now!

                  這篇關于從 Google OAuth 2.0 PHP API 獲取用戶信息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='HSlyv'></small><noframes id='HSlyv'>

                      <tfoot id='HSlyv'></tfoot>

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

                          <legend id='HSlyv'><style id='HSlyv'><dir id='HSlyv'><q id='HSlyv'></q></dir></style></legend>
                          主站蜘蛛池模板: 汽液过滤网厂家_安平县银锐丝网有限公司 | 散热器-电子散热器-型材散热器-电源散热片-镇江新区宏图电子散热片厂家 | 全自动五线打端沾锡机,全自动裁线剥皮双头沾锡机,全自动尼龙扎带机-东莞市海文能机械设备有限公司 | 考试试题_试卷及答案_诗词单词成语 - 优易学 | 志高装潢官网-苏州老房旧房装修改造-二手房装修翻新 | 喷漆房_废气处理设备-湖北天地鑫环保设备有限公司 | 快速卷帘门_硬质快速卷帘门-西朗门业 | 口臭的治疗方法,口臭怎么办,怎么除口臭,口臭的原因-口臭治疗网 | 煤矿支护网片_矿用勾花菱形网_缝管式_管缝式锚杆-邯郸市永年区志涛工矿配件有限公司 | 美侍宠物-专注宠物狗及宠物猫训练|喂养|医疗|繁育|品种|价格 | 环氧树脂地坪_防静电地坪漆_环氧地坪漆涂料厂家-地壹涂料地坪漆 环球电气之家-中国专业电气电子产品行业服务网站! | 沈阳网站建设_沈阳网站制作_沈阳网页设计-做网站就找示剑新零售 沈阳缠绕膜价格_沈阳拉伸膜厂家_沈阳缠绕膜厂家直销 | 潜水搅拌机-双曲面搅拌机-潜水推进器|奥伯尔环保 | 炉门刀边腹板,焦化设备配件,焦化焦炉设备_沧州瑞创机械制造有限公司 | 河北中仪伟创试验仪器有限公司是专业生产沥青,土工,水泥,混凝土等试验仪器的厂家,咨询电话:13373070969 | 变频器维修公司_plc维修_伺服驱动器维修_工控机维修 - 夫唯科技 变位机,焊接变位机,焊接变位器,小型变位机,小型焊接变位机-济南上弘机电设备有限公司 | 医养体检包_公卫随访箱_慢病随访包_家签随访包_随访一体机-济南易享医疗科技有限公司 | 天津蒸汽/热水锅炉-电锅炉安装维修直销厂家-天津鑫淼暖通设备有限公司 | 粘度计NDJ-5S,粘度计NDJ-8S,越平水分测定仪-上海右一仪器有限公司 | 精密模具制造,注塑加工,吹塑和吹瓶加工,EPS泡沫包装生产 - 济南兴田塑胶有限公司 | 锌合金压铸-铝合金压铸厂-压铸模具-冷挤压-誉格精密压铸 | 南京和瑞包装有限公司| 成都软件开发_OA|ERP|CRM|管理系统定制开发_成都码邻蜀科技 | 污泥烘干机-低温干化机-工业污泥烘干设备厂家-焦作市真节能环保设备科技有限公司 | 工作服定制,工作服定做,工作服厂家-卡珀职业服装(苏州)有限公司 | vr安全体验馆|交通安全|工地安全|禁毒|消防|安全教育体验馆|安全体验教室-贝森德(深圳)科技 | 卧涛科技有限公司科技项目申报公司|高新技术企业申报|专利申请 | Brotu | 关注AI,Web3.0,VR/AR,GPT,元宇宙区块链数字产业 | 威客电竞(vk·game)·电子竞技赛事官网 | 仿古瓦,仿古金属瓦,铝瓦,铜瓦,铝合金瓦-西安东申景观艺术工程有限公司 | pbt头梳丝_牙刷丝_尼龙毛刷丝_PP塑料纤维合成毛丝定制厂_广州明旺 | 定制异形重型钢格栅板/钢格板_定做踏步板/排水沟盖板_钢格栅板批发厂家-河北圣墨金属制品有限公司 | 水厂污泥地磅|污泥处理地磅厂家|地磅无人值守称重系统升级改造|地磅自动称重系统维修-河南成辉电子科技有限公司 | 自恢复保险丝_贴片保险丝_力特保险丝_Littelfuse_可恢复保险丝供应商-秦晋电子 | 包塑丝_高铁绑丝_地暖绑丝_涂塑丝_塑料皮铁丝_河北创筹金属丝网制品有限公司 | 耐酸碱泵-自吸耐酸碱泵型号「品牌厂家」立式耐酸碱泵价格-昆山国宝过滤机有限公司首页 | 美甲贴片-指甲贴片-穿戴美甲-假指甲厂家--薇丝黛拉 | 济南画室培训-美术高考培训-山东艺霖艺术培训画室 | 冷却塔降噪隔音_冷却塔噪声治理_冷却塔噪音处理厂家-广东康明冷却塔降噪厂家 | 昆明挖掘机修理厂_挖掘机翻新再制造-昆明聚力工程机械维修有限公司 | 东莞韩创-专业绝缘骨架|马达塑胶零件|塑胶电机配件|塑封电机骨架厂家 |