/** * Return Google Content Client Instance * * @param int $storeId * @param bool $noAuthRedirect * * @return bool|Google_Client */ public function getClient($storeId, $noAuthRedirect = false) { if (isset($this->_client)) { if ($this->_client->isAccessTokenExpired()) { return $this->redirectToAuth($storeId, $noAuthRedirect); } return $this->_client; } $clientId = $this->getConfig()->getConfigData('client_id', $storeId); $clientSecret = $this->getConfig()->getClientSecret($storeId); $accessToken = $this->_getAccessToken($storeId); if (!$clientId || !$clientSecret) { Mage::getSingleton('adminhtml/session')->addError("Please specify Google Content API access data for this store!"); return false; } if (!isset($accessToken) || empty($accessToken)) { return $this->redirectToAuth($storeId, $noAuthRedirect); } $this->_client = new Google_Client(); $this->_client->setApplicationName(self::APPNAME); $this->_client->setClientId($clientId); $this->_client->setClientSecret($clientSecret); $this->_client->setScopes('https://www.googleapis.com/auth/content'); $this->_client->setAccessToken($accessToken); if ($this->_client->isAccessTokenExpired()) { return $this->redirectToAuth($storeId, $noAuthRedirect); } if ($this->getConfig()->getIsDebug($storeId)) { $this->_client->setLogger(Mage::getModel('gshoppingv2/logger', $this->_client)->setStoreID($storeId)); } return $this->_client; }
/** * @param KalturaYoutubeApiDistributionJobProviderData $providerData * @return Google_Client */ protected function initClient(KalturaYoutubeApiDistributionProfile $distributionProfile) { $options = array(CURLOPT_VERBOSE => true, CURLOPT_STDERR => STDOUT, CURLOPT_TIMEOUT => $this->timeout); $client = new Google_Client(); $client->getIo()->setOptions($options); $client->setLogger(new YoutubeApiDistributionEngineLogger($client)); $client->setClientId($distributionProfile->googleClientId); $client->setClientSecret($distributionProfile->googleClientSecret); $client->setAccessToken(str_replace('\\', '', $distributionProfile->googleTokenData)); return $client; }
/** * @param array $config */ public function __construct(array $config, LoggerInterface $symfonyLogger = null) { // True if objects should be returned by the service classes. // False if associative arrays should be returned (default behavior). $config['use_objects'] = true; $client = new \Google_Client($config); if ($symfonyLogger) { //BC for Google API 1.0 if (class_exists('\\Google_Logger_Psr')) { $googleLogger = new \Google_Logger_Psr($client, $symfonyLogger); $client->setLogger($googleLogger); } else { $client->setLogger($symfonyLogger); } } $client->setApplicationName($config['application_name']); $client->setClientId($config['oauth2_client_id']); $client->setClientSecret($config['oauth2_client_secret']); $client->setRedirectUri($config['oauth2_redirect_uri']); $client->setDeveloperKey($config['developer_key']); $this->client = $client; }
/** * Initialize API to Google and YouTube * * @param string $oAuthRedirectUrl * @throws LiveBroadcastOutputException */ public function initApiClients($oAuthRedirectUrl) { if (empty($this->clientId) || empty($this->clientSecret)) { throw new LiveBroadcastOutputException('The YouTube oAuth settings are not correct.'); } $googleApiClient = new \Google_Client(); $googleApiClient->setLogger($this->logger); $googleApiClient->setClientId($this->clientId); $googleApiClient->setClientSecret($this->clientSecret); $googleApiClient->setScopes('https://www.googleapis.com/auth/youtube'); $googleApiClient->setAccessType('offline'); $googleApiClient->setRedirectUri($oAuthRedirectUrl); $googleApiClient->setApprovalPrompt('force'); $this->googleApiClient = $googleApiClient; $this->youTubeApiClient = new \Google_Service_YouTube($googleApiClient); }
}; // [END session] // add AppEngineFlexHandler on prod // [START logging] $app->register(new Silex\Provider\MonologServiceProvider()); if (isset($_SERVER['GAE_VM']) && $_SERVER['GAE_VM'] === 'true') { $app['monolog.handler'] = new AppEngineFlexHandler(); } else { $app['monolog.handler'] = new Monolog\Handler\ErrorLogHandler(); } // [END logging] // create the google authorization client // [START google_client] $app['google_client'] = function ($app) { $client = new Google_Client(['client_id' => $app['config']['google_client_id'], 'client_secret' => $app['config']['google_client_secret']]); $client->setLogger($app['monolog']); if ($app['routes']->get('login_callback')) { /** @var Symfony\Component\Routing\Generator\UrlGenerator $urlGen */ $urlGen = $app['url_generator']; $redirectUri = $urlGen->generate('login_callback', [], $urlGen::ABSOLUTE_URL); $client->setRedirectUri($redirectUri); } return $client; }; // [END google_client] // [START pubsub_client] $app['pubsub.client'] = function ($app) { // create the pubsub client $projectId = $app['config']['google_project_id']; $pubsub = new PubSubClient(['projectId' => $projectId]); return $pubsub;