私は Symfony2.3 を使用しており、Google カレンダー API にアクセスしたいのですが、ここで私がしたこと 1- HIWO バンドルとFOSUser バンドル
をインストールしました
2-両方のバンドルを統合し、ユーザーが認証され、アクセストークンでデータベースに挿入されましたGoogle API ライブラリをインストールして自動ロード 4-アクセスするサービス ラッパー クラスを作成
問題 1 : ログイン中に HIWO Bundle にある Oauth2 を使用しているようで、リクエストを作成するときに Google API ライブラリで Oauth2 を使用しますが、これは意味がなく、この問題で何をすべきかわかりません
試行:
-HIW Oauth によって提供されたトークンが、リダイレクト中に URL のパラメーターのトークンと同じではないことがわかりました-手動でトークンを設定しようとし、以下のようにcode
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