我正在使用 Symfony2.3 并且我想访问 Google Calendar API,在这里我做了什么 1-我安装了HIWO Bundle和FOSUser Bundle
2-集成了两个捆绑包,现在我已经通过访问令牌进行了用户身份验证并插入到数据库中 3-我有安装Google API 库并自动加载它 4-创建一个服务包装类来访问
问题 1: 现在似乎我在登录时使用 HIWO Bundle 中的 Oauth2,我将在发出请求时在 Google API 库中使用 Oauth2,这没有任何意义,并且不确定在这件事上应该做什么
试验:
-我发现 HIW Oauth 提供的令牌与code
重定向回 URL 中的参数中的令牌不同 -尝试手动设置令牌并尝试启动模拟 Google 客户端请求$cal = new \Google_Calendar($this->googleClient)
,如下所示,但是
$this->googleClient->authenticate('4/PmsUDPCbxWgL1X_akVYAhvnVWqpn.ErqFdB3R6wMTOl05ti8ZT3Zpgre8fgI');
return $cal->calendarList->listCalendarList();`
收到错误:
获取 OAuth2 访问令牌时出错,消息:“redirect_uri_mismatch”
我确定我已经redirect_uri
匹配了
我的服务代码如下:
<?php
namespace Clinic\MainBundle\Services;
use Clinic\MainBundle\Entity\Patient;
use Doctrine\Common\Persistence\ObjectManager;
/*
* @author: Ahmed Samy
*/
class GoogleInterfaceService {
/*
* Entity manager
*/
protected $em;
/*
* instance of Symfphony session
*/
protected $session;
/*
* Service container
*/
protected $container;
/*
* Google client instance
*/
protected $googleClient;
public function __construct(ObjectManager $em, $container) {
$this->em = $em;
$this->container = $container;
$this->googleClient = new \Google_Client();
$this->googleClient->setClientId('xxxxxxxx.apps.googleusercontent.com');
$this->googleClient->setClientSecret('uNnaK1o-sGH_pa6Je2jfahpz');
$this->googleClient->setRedirectUri('http://hacdc.com/app_dev.php/login/check-google');
$this->googleClient->setDeveloperKey('xxxxxxxxxxxxxxxxxxxx');
$this->googleClient->setApplicationName("Google Calendar PHP Starter Application");
}
public function getCalendar() {
$cal = new \Google_Calendar($this->googleClient);
//setting token manually
$this->googleClient->authenticate('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
return $cal->calendarList->listCalendarList();
}
}
当我倾倒$this->googleClient
我得到
protected 'scopes' =>
array (size=0)
empty
protected 'useObjects' => boolean false
protected 'services' =>
array (size=0)
empty
private 'authenticated' => boolean false