0

私は Symfony2.3 を使用しており、Google カレンダー API にアクセスしたいのですが、ここで私がしたこと 1- HIWO バンドルFOSUser バンドル
をインストールしました 2-両方のバンドルを統合し、ユーザーが認証され、アクセストークンでデータベースに挿入されましたGoogle API ライブラリをインストールして自動ロード 4-アクセスするサービス ラッパー クラスを作成

問題 1 : ログイン中に HIWO Bundle にある Oauth2 を使用しているようで、リクエストを作成するときに Google API ライブラリで Oauth2 を使用しますが、これは意味がなく、この問題で何をすべきかわかりません

試行: -HIW Oauth によって提供されたトークンが、リダイレクト中に URL のパラメーターのトークンと同じではないことがわかりました-手動でトークンを設定しようとし、以下のようにcodeGoogle クライアント要求をシミュレートしようとしましたが、$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
4

1 に答える 1

0

HWIOAuthBundle のトークンにはcreated配列セグメントがありませんが、そこにそれを強制して、そのトークンを次のようにクライアントにフィードすることができます。

    $googleAccessToken = $this->get('security.context')->getToken()->getRawToken();
    $googleAccessToken['created'] = time(); // This is obviously wrong... but you get the poing

    $this->google_client->setAccessToken(json_encode($googleAccessToken));

    $activities = $this->google_plusservice->activities->listActivities('me', 'public');

    var_dump($activities);die();
于 2013-09-24T16:45:43.583 に答える