本文整理汇总了PHP中Google_Client::setDeveloperKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_Client::setDeveloperKey方法的具体用法?PHP Google_Client::setDeveloperKey怎么用?PHP Google_Client::setDeveloperKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google_Client
的用法示例。
在下文中一共展示了Google_Client::setDeveloperKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: make
/**
* @param string $name
* @return \League\Flysystem\AdapterInterface
* @throws \RuntimeException
*/
public static function make($name)
{
$connections = Config::get('storage.connections');
if (!isset($connections[$name])) {
throw new \RuntimeException(sprintf('The storage connection %d does not exist.', $name));
}
$connection = $connections[$name];
$connection['adapter'] = strtoupper($connection['adapter']);
switch ($connection['adapter']) {
case 'LOCAL':
return new Local($connection['root_path'], $connection['public_url_base']);
case 'RACKSPACE':
$service = isset($connection['service']) ? Config::get($connection['service']) : Config::get('services.rackspace');
$client = new Rackspace($service['api_endpoint'], array('username' => $service['username'], 'tenantName' => $service['tenant_name'], 'apiKey' => $service['api_key']));
$store = $client->objectStoreService($connection['store'], $connection['region']);
$container = $store->getContainer($connection['container']);
return new RackspaceAdapter($container);
case 'AWS':
$service = isset($connection['service']) ? Config::get($connection['service']) : Config::get('services.aws');
$client = S3Client::factory(array('credentials' => array('key' => $service['access_key'], 'secret' => $service['secret_key']), 'region' => $service['region'], 'version' => 'latest'));
return new AwsS3Adapter($client, $connection['bucket']);
case 'GCLOUD':
$service = isset($connection['service']) ? Config::get($connection['service']) : Config::get('services.google_cloud');
$credentials = new \Google_Auth_AssertionCredentials($service['service_account'], [\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL], file_get_contents($service['key_file']), $service['secret']);
$config = new \Google_Config();
$config->setAuthClass(GoogleAuthOAuth2::class);
$client = new \Google_Client($config);
$client->setAssertionCredentials($credentials);
$client->setDeveloperKey($service['developer_key']);
$service = new \Google_Service_Storage($client);
return new GoogleStorageAdapter($service, $connection['bucket']);
}
throw new \RuntimeException(sprintf('The storage adapter %s is invalid.', $connection['adapter']));
}
示例2: execute
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var \Doctrine\ORM\EntityManager $em */
$em = $this->getContainer()->get('doctrine.orm.default_entity_manager');
$campaignRepo = $em->getRepository('VifeedCampaignBundle:Campaign');
$campaigns = new ArrayCollection($campaignRepo->getActiveCampaigns());
$hashes = [];
foreach ($campaigns as $campaign) {
/** @var Campaign $campaign */
$hashes[] = $campaign->getHash();
}
$hashes = array_unique($hashes);
$client = new \Google_Client();
$client->setDeveloperKey($this->getContainer()->getParameter('google.api.key'));
$youtube = new \Google_Service_YouTube($client);
/* Опытным путём выяснилось, что ютуб принимает не больше 50 хешей за раз */
$hash = 'TjvivnmWcn4';
$request = $youtube->videos->listVideos('status', ['id' => $hash]);
foreach ($request as $video) {
/** @var \Google_Service_YouTube_Video $video */
/** @var \Google_Service_YouTube_VideoStatistics $stats */
$stats = $video->getStatistics();
$hash = $video->getId();
/* не исключается ситуация, что может быть несколько кампаний с одинаковым hash */
$filteredCampaigns = $campaigns->filter(function (Campaign $campaign) use($hash) {
return $campaign->getHash() == $hash;
});
foreach ($filteredCampaigns as $campaign) {
$campaign->setSocialData('youtubeViewCount', $stats->getViewCount())->setSocialData('youtubeCommentCount', $stats->getCommentCount())->setSocialData('youtubeFavoriteCount', $stats->getFavoriteCount())->setSocialData('youtubeLikeCount', $stats->getLikeCount())->setSocialData('youtubeDislikeCount', $stats->getDislikeCount());
$em->persist($campaign);
}
}
$em->flush();
}
示例3: __construct
/**
* Create a new Google instance.
*
* @param array $config
*
* @return void
*/
public function __construct(array $config)
{
$this->config = $config;
$this->client = new \Google_Client();
$this->client->setApplicationName("Tag media Mrs");
$this->client->setDeveloperKey($config['developer_key']);
}
示例4:
function __construct($API_SERVER_TOKEN)
{
$this->apiClient = new \Google_Client();
$this->apiClient->setApplicationName("EHF-YouTube-Playlist");
$this->apiClient->setDeveloperKey($API_SERVER_TOKEN);
$this->apiService = new \Google_Service_YouTube($this->apiClient);
}
示例5: __construct
public function __construct(ContainerInterface $container, $api_key, $project_name)
{
$this->service_container = $container;
$this->client = new \Google_Client();
$this->client->setApplicationName($project_name);
$this->client->setDeveloperKey($api_key);
$this->searcher = new \Google_Service_Books($this->client);
}
示例6: __construct
/**
* @param \Google_Client $client
*/
public function __construct(\Google_Client $client)
{
$this->client = $client;
$this->client->setClientId(\Config::get('google.client_id'));
$this->client->setClientSecret(\Config::get('google.client_secret'));
$this->client->setDeveloperKey(\Config::get('google.api_key'));
$this->client->setRedirectUri(\Config::get('app.url') . "/loginCallback");
$this->client->setScopes(['https://www.googleapis.com/auth/youtube']);
$this->client->setAccessType('offline');
}
示例7: init_youtube_service
/**
* Init all the youtube client service stuff.
*
* Instead of instantiating the service in the constructor, we delay
* it until really neeed because it's really memory hungry (2MB). That
* way the editor or any other artifact requiring repository instantiation
* can do it in a cheap way. Sort of lazy loading the plugin.
*/
private function init_youtube_service()
{
global $CFG;
if (!isset($this->service)) {
require_once $CFG->libdir . '/google/lib.php';
$this->client = get_google_client();
$this->client->setDeveloperKey($this->apikey);
$this->client->setScopes(array(Google_Service_YouTube::YOUTUBE_READONLY));
$this->service = new Google_Service_YouTube($this->client);
}
}
示例8: init_m27tube_service
/**
* Init all the m27tube client service stuff.
*
* Instead of instantiating the service in the constructor, we delay
* it until really neeed because it's really memory hungry (2MB). That
* way the editor or any other artifact requiring repository instantiation
* can do it in a cheap way. Sort of lazy loading the plugin.
*/
private function init_m27tube_service()
{
global $CFG;
if (!isset($this->service)) {
require_once $CFG->dirroot . '/repository/m27tube/google/lib.php';
require_once $CFG->dirroot . '/repository/m27tube/google/Google/Service/YouTube.php';
$this->client = get_google_client();
$this->client->setDeveloperKey($this->apikey);
$this->client->setScopes(array(Google_Service_YouTube::YOUTUBE_READONLY));
$this->service = new Google_Service_YouTube($this->client);
}
}
示例9: initializeClient
public function initializeClient()
{
$this->client = new Client();
$this->client->setAccessType('offline');
$this->client->setApplicationName('playlister');
$this->client->setClientId($this->config->get('services.youtube.client_id'));
$this->client->setClientSecret($this->config->get('services.youtube.client_secret'));
$this->client->setRedirectUri($this->config->get('services.youtube.redirect'));
$this->client->setDeveloperKey($this->config->get('services.youtube.api_key'));
$this->client->addScope('https://www.googleapis.com/auth/youtube.readonly');
if ($this->auth->check() && $this->request->session()->has('user.token')) {
$this->setToken($this->request->session()->get('user.token'));
}
}
示例10: newYoutubeService
function newYoutubeService($key)
{
$client = new Google_Client();
$client->setDeveloperKey($key);
$service = new Google_Service_YouTube($client);
return $service;
}
示例11: actionRefresh
public function actionRefresh()
{
echo "hi";
$DEVELOPER_KEY = 'AIzaSyCzTX4jeGnhS1Cvkz0KP-1rFf9EnYhrVJM';
$client = new \Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
$youtube = new \Google_Service_YouTube($client);
try {
$searchResponse = $youtube->search->listSearch('id,snippet', array('maxResults' => 5));
$videoResults = array();
foreach ($searchResponse['items'] as $searchResult) {
array_push($videoResults, $searchResult['id']['videoId']);
}
$videoIds = join(',', $videoResults);
$videosResponse = $youtube->videos->listVideos('snippet, statistics', array('id' => $videoIds));
Yii::$app->db->createCommand('TRUNCATE videos')->execute();
for ($i = 0; $i < sizeof($videosResponse); $i++) {
$channelsResponse = $youtube->channels->listChannels('statistics', array('id' => $videosResponse[$i]['snippet']['channelId']));
Yii::$app->db->createCommand()->insert('videos', ['id_video' => $videosResponse[$i]['id'], 'id_channel' => $videosResponse[$i]['snippet']['channelId'], 'video_title' => $videosResponse[$i]['snippet']['title'], 'channel_title' => $videosResponse[$i]['snippet']['channelTitle'], 'video_description' => $videosResponse[$i]['snippet']['description'], 'video_thumbnail' => $videosResponse[$i]['snippet']['thumbnails']['medium']['url'], 'views_count' => $videosResponse[$i]['statistics']['viewCount'], 'comments_count' => $videosResponse[$i]['statistics']['commentCount'], 'likes_count' => $videosResponse[$i]['statistics']['likeCount'], 'dislikes_count' => $videosResponse[$i]['statistics']['dislikeCount'], 'subscribers_count' => $channelsResponse[0]['statistics']['subscriberCount']])->execute();
}
return null;
} catch (Google_Service_Exception $e) {
echo sprintf('<p>A service error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
} catch (Google_Exception $e) {
echo sprintf('<p>An client error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
}
}
示例12: callback
public function callback()
{
$client = new Google_Client();
$client->setApplicationName($this->__app_name);
$client->setClientId($this->__client_id);
$client->setClientSecret($this->__client_secret);
$client->setRedirectUri($this->__redirect_uri);
$client->setDeveloperKey($this->__develop_key);
$client->setScopes('https://www.googleapis.com/auth/calendar');
$client->setAccessType('offline');
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
$this->Session->delete('HTTP_REFERER');
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
// 呼び出し先
if (isset($_SESSION['oauth_referer'])) {
$url = $_SESSION['oauth_referer'];
$this->Session->delete('oauth_referer');
} else {
$url = 'index';
}
$this->redirect('/');
}
示例13: index
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$client = new \Google_Client();
$client->setDeveloperKey(getenv('GOOGLE_API_KEY'));
// Define an object that will be used to make all API requests.
$youtube = new \Google_Service_YouTube($client);
$videoIds = "";
$videos = [];
foreach (Auth::user()->channels as $channel) {
// Call the search.list method to retrieve results matching the specified
// query term.
$searchResponse = $youtube->search->listSearch('id', array('channelId' => $channel->youtube_id));
// Add each result to the appropriate list, and then display the lists of
// matching videos, channels, and playlists.
foreach ($searchResponse['items'] as $searchResult) {
if ($searchResult['id']['kind'] == 'youtube#video') {
$videoIds .= $searchResult['id']['videoId'] . ",";
}
}
}
$searchResponse = $youtube->videos->listVideos('snippet,statistics', array('id' => $videoIds));
foreach ($searchResponse['items'] as $searchResult) {
$videos[] = new Video(['title' => $searchResult['snippet']['title'], 'videoId' => $searchResult['id'], 'channelId' => $searchResult['snippet']['channelId'], 'channelTitle' => $searchResult['snippet']['channelTitle'], 'description' => $searchResult['snippet']['description'], 'publishedAt' => $searchResult['snippet']['publishedAt'], 'thumbnail' => $searchResult['snippet']['modelData']['thumbnails']['default']['url'], 'thumbnailWidth' => $searchResult['snippet']['modelData']['thumbnails']['default']['width'], 'thumbnailHeight' => $searchResult['snippet']['modelData']['thumbnails']['default']['height'], 'viewCount' => $searchResult['statistics']['viewCount'], 'likeCount' => $searchResult['statistics']['likeCount'], 'dislikeCount' => $searchResult['statistics']['dislikeCount'], 'favoriteCount' => $searchResult['statistics']['favoriteCount'], 'commentCount' => $searchResult['statistics']['commentCount'], 'rawData' => $searchResult]);
}
//$videos = usort($videos, [Video::class, "cmp"]);
return view('home', compact('videos'));
}
示例14: getYouTubeVideos
public function getYouTubeVideos($maxResults = 5)
{
$client = new Google_Client();
$client->setDeveloperKey(self::$apiKey);
$youtube = new Google_Service_YouTube($client);
try {
$searchResponse = $youtube->search->listSearch('id,snippet', array('type' => 'video', 'q' => urlencode($this->keyword), 'maxResults' => $maxResults, 'order' => 'viewCount'));
$videos = array();
$videoIds = array();
foreach ($searchResponse['items'] as $result) {
array_push($videoIds, $result['id']['videoId']);
$videos[$result['id']['videoId']] = array('url' => $this->youtubeBaseURL . $result['id']['videoId'], 'thumbnail' => $result['snippet']['thumbnails']['high']['url']);
}
$videoResponse = $youtube->videos->listVideos('id,contentDetails,statistics', array('id' => join(',', $videoIds)));
foreach ($videoResponse['items'] as $videoResult) {
$duration = $this->getYouTubeDurations($videoResult['contentDetails']['duration']);
$videos[$videoResult['id']]['duration'] = "{$duration[0]}:{$duration[1]}";
$videos[$videoResult['id']]['views'] = $videoResult['statistics']['viewCount'];
}
return $videos;
} catch (Google_Service_Exception $e) {
die(sprintf('<p>A service error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage())));
} catch (Google_Exception $e) {
die(sprintf('<p>An client error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage())));
}
return null;
}
示例15: googlecallback
public function googlecallback()
{
$ret = null;
//$google_redirect_url = site_url('user/signup');
$google_redirect_url = 'http://localhost/punu/punu/index.php/user/signup';
$client = new Google_Client();
$client->setClientId($this->google_client_id);
$client->setClientSecret($this->google_client_secret);
$client->setDeveloperKey($this->google_api_key);
$client->setRedirectUri($google_redirect_url);
$client->addScope($this->google_scope);
// Send Client Request
$objOAuthService = new Google_Service_Oauth2($client);
// Add Access Token to Session
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['google_access_token'] = $client->getAccessToken();
//header('Location: ' . filter_var($this->google_redirect_url, FILTER_SANITIZE_URL));
}
// Set Access Token to make Request
if (isset($_SESSION['google_access_token']) && $_SESSION['google_access_token']) {
$client->setAccessToken($_SESSION['google_access_token']);
}
// Get User Data from Google and store them in $data
if ($client->getAccessToken()) {
$userData = $objOAuthService->userinfo->get();
//$_SESSION['userData'] = $userData;
$_SESSION['google_access_token'] = $client->getAccessToken();
$ret = $userData;
}
return $ret;
}