Zend framework 如何获取用户';使用谷歌+;Zend Framework1中的API?

Zend framework 如何获取用户';使用谷歌+;Zend Framework1中的API?,zend-framework,google-api,google-plus,google-oauth,google-authentication,Zend Framework,Google Api,Google Plus,Google Oauth,Google Authentication,我在我的示例中集成了Google API,通过Google+登录我的网站,从用户的个人资料中获取用户电子邮件、名字和姓氏的详细信息。当我使用下面的函数时 public function getProfile() { $endpoint = 'https://www.googleapis.com/oauth2/v1/userinfo'; return (array) json_decode($this->_getData('profile', $endpoint

我在我的示例中集成了Google API,通过Google+登录我的网站,从用户的个人资料中获取用户电子邮件、名字和姓氏的详细信息。当我使用下面的函数时

    public function getProfile()
   {
    $endpoint = 'https://www.googleapis.com/oauth2/v1/userinfo';
    return (array) json_decode($this->_getData('profile', $endpoint));
   }
我得到的输出是

    Array ( [firstname] => xxxx [appid] => 11XXXXXXXXXXXXXXXXX92 [email] => [lastname] => YYYY [location] => [username] => XXXX YYYY )
其中,
电子邮件
为空


如何获取电子邮件id?要获取电子邮件id和其他数据,必须在此处的
$endpoint
中写入什么uri?

您没有显示您请求的范围,但似乎没有请求范围

但是,userinfo作用域和端点已被弃用,将于2014年9月删除


接下来,您应该将电子邮件作用域与其中一个配置文件作用域(如profile,or)一起使用以访问用户的电子邮件,然后使用其中一个Google+API端点,如用户名为“me”的端点。如果您请求
电子邮件
作用域,则囚犯是正确的,您将能够在
plus.people.get
API调用中获取用户的电子邮件地址。我将向您展示如何使用JavaScript执行此操作:

在结束body标记之前添加带有以下代码的Google API,这很难看,但却是异步加载外部库的标准:

<script type="text/javascript">
  (function() {
    var po = document.createElement('script');
    po.type = 'text/javascript'; po.async = true;
    po.src = 'https://plus.google.com/js/client:plusone.js';
    var s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(po, s);
  })();
</script>

加载Google+API客户端并处理身份验证响应:

function onSignInCallback(){
  gapi.client.load('plus','v1', function(){
    if (authResult['access_token']) {
      gapi.client.plus.people.get({'userId':'me'}).execute(
        function(resp){
          alert(resp.emails[0].value)
        });          
    } else if (authResult['error']) {
      // There was an error, which means the user is not signed in.
      // As an example, you can handle by writing to the console:
      console.log('There was an error: ' + authResult['error']);
    }
    console.log('authResult', authResult);
  });
}

  gapi.client.load('plus','v1', function(){
    if (authResult['access_token']) {
      gapi.client.plus.people.get({'userId':'me'}).execute(
        function(resp){
          alert(resp.emails[0].value)
        });          
    } else if (authResult['error']) {
      // There was an error, which means the user is not signed in.
      // As an example, you can handle by writing to the console:
      console.log('There was an error: ' + authResult['error']);
    }
    console.log('authResult', authResult);
  });
}