本文整理汇总了PHP中apiClient::getAccessToken方法的典型用法代码示例。如果您正苦于以下问题:PHP apiClient::getAccessToken方法的具体用法?PHP apiClient::getAccessToken怎么用?PHP apiClient::getAccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apiClient
的用法示例。
在下文中一共展示了apiClient::getAccessToken方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionDefault
public function actionDefault()
{
$google_config = NEnvironment::getConfig()->google;
require_once LIBS_DIR . '/google-api-php-client/src/apiClient.php';
require_once LIBS_DIR . '/google-api-php-client/src/contrib/apiOauth2Service.php';
require_once LIBS_DIR . '/google-api-php-client/src/contrib/apiAnalyticsService.php';
$client = new apiClient();
$client->setApplicationName('Google+ PHP Starter Application');
// Visit https://code.google.com/apis/console?api=plus to generate your
// client id, client secret, and to register your redirect uri.
// $client->setClientId( $google_config['client_id'] );
// $client->setClientSecret( $google_config['client_secret'] );
$client->setRedirectUri($google_config['redirect_url']);
// $client->setDeveloperKey('AIzaSyCrViGDrmXAiLsQAoW1aOzkHddH9gHYzzs');
// [8] => Array
// (
// [title] => www.propagacnepredmety.sk
// [entryid] => http://www.google.com/analytics/feeds/accounts/ga:43556790
// [accountId] => 17205615
// [accountName] => www.vizion.sk
// [profileId] => 43556790
// [webPropertyId] => UA-17205615-3
// [tableId] => ga:43556790
// )
$ga = new apiAnalyticsService($client);
if (isset($_GET['code'])) {
$ga->authenticate();
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if ($client->getAccessToken()) {
$activities = $plus->activities->listActivities('me', 'public');
print 'Your Activities: <pre>' . print_r($activities, true) . '</pre>';
// The access token may have been updated.
$_SESSION['token'] = $client->getAccessToken();
} else {
$authUrl = $client->createAuthUrl();
print "<a class='login' href='{$authUrl}'>Connect Me!</a>";
}
// $_SESSION['token'] = $client->getAccessToken();
$data = $ga->data_ga;
$d = $data->get('17205615', date('Y-m-d', time() - 60 * 60 * 24 * 40), date('Y-m-d', time() - 60 * 60 * 24 * 1), 'ga:visits,ga:pageviews');
print_r($d);
exit;
}
示例2: testSettersGetters
public function testSettersGetters()
{
$client = new apiClient();
$client->setClientId("client1");
$client->setClientSecret('client1secret');
$client->setState('1');
$client->setApprovalPrompt('force');
$client->setAccessType('offline');
global $apiConfig;
$this->assertEquals('client1', $apiConfig['oauth2_client_id']);
$this->assertEquals('client1secret', $apiConfig['oauth2_client_secret']);
$client->setRedirectUri('localhost');
$client->setApplicationName('me');
$client->setUseObjects(false);
$this->assertEquals('object', gettype($client->getAuth()));
$this->assertEquals('object', gettype($client->getCache()));
$this->assertEquals('object', gettype($client->getIo()));
$client->setAuthClass('apiAuthNone');
$client->setAuthClass('apiOAuth2');
try {
$client->setAccessToken(null);
die('Should have thrown an apiAuthException.');
} catch (apiAuthException $e) {
$this->assertEquals('Could not json decode the access token', $e->getMessage());
}
$token = json_encode(array('access_token' => 'token'));
$client->setAccessToken($token);
$this->assertEquals($token, $client->getAccessToken());
}
示例3: index
public function index()
{
$this->id = "content";
$this->template = "login/login.tpl";
$this->layout = "common/layout";
$request = Registry::get('request');
$db = Registry::get('db');
$session = Registry::get('session');
$this->load->model('user/auth');
$this->load->model('user/user');
$this->load->model('user/prefs');
$this->load->model('user/google');
$this->load->model('domain/domain');
$this->load->model('folder/folder');
$this->document->title = $this->data['text_login'];
$client = new apiClient();
$client->setApplicationName(GOOGLE_APPLICATION_NAME);
$client->setScopes(array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'https://mail.google.com/'));
$client->setClientId(GOOGLE_CLIENT_ID);
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
$client->setRedirectUri(GOOGLE_REDIRECT_URL);
$client->setDeveloperKey(GOOGLE_DEVELOPER_KEY);
$oauth2 = new apiOauth2Service($client);
if (isset($_GET['code'])) {
$client->authenticate();
$session->set("access_token", $client->getAccessToken());
header('Location: ' . GOOGLE_REDIRECT_URL);
}
if ($session->get("access_token")) {
$client->setAccessToken($session->get("access_token"));
}
if ($client->getAccessToken()) {
$session->set("access_token", $client->getAccessToken());
$token = json_decode($session->get("access_token"));
if (isset($token->{'access_token'}) && isset($token->{'refresh_token'})) {
$account = $oauth2->userinfo->get();
$this->model_user_google->check_for_account($account);
$this->model_user_google->update_tokens($account['email'], $account['id'], $token);
header("Location: " . SITE_URL . "search.php");
exit;
}
}
$this->render();
}
示例4: __construct
public function __construct()
{
global $apiConfig, $apiClient, $pageSpeedService;
parent::__construct();
if (!$apiClient || !$pageSpeedService) {
$this->origConfig = $apiConfig;
// Set up a predictable, default environment so the test results are predictable
//$apiConfig['oauth2_client_id'] = 'INSERT_CLIENT_ID';
//$apiConfig['oauth2_client_secret'] = 'INSERT_CLIENT_SECRET';
$apiConfig['authClass'] = 'apiOAuth2';
$apiConfig['ioClass'] = 'apiCurlIO';
$apiConfig['cacheClass'] = 'apiFileCache';
$apiConfig['ioFileCache_directory'] = '/tmp/googleApiTests';
$apiClient = new apiClient();
$pageSpeedService = new apiPagespeedonlineService($apiClient);
if (!$apiClient->getAccessToken()) {
$apiClient->setAccessToken($apiConfig['oauth_test_token']);
}
}
$this->apiClient = $apiClient;
$this->pageSpeedService = $pageSpeedService;
}
示例5: __construct
public function __construct()
{
global $apiConfig, $apiBuzzTest_apiClient, $apiBuzzTest_buzz;
parent::__construct();
if (!$apiBuzzTest_apiClient || !$apiBuzzTest_buzz) {
$this->origConfig = $apiConfig;
// Set up a predictable, default environment so the test results are predictable
//$apiConfig['oauth2_client_id'] = 'INSERT_CLIENT_ID';
//$apiConfig['oauth2_client_secret'] = 'INSERT_CLIENT_SECRET';
$apiConfig['authClass'] = 'apiOAuth2';
$apiConfig['ioClass'] = 'apiCurlIO';
$apiConfig['cacheClass'] = 'apiFileCache';
$apiConfig['ioFileCache_directory'] = '/tmp/googleApiTests';
// create the global api and buzz clients (which are shared between the various buzz test suites for performance reasons)
$apiBuzzTest_apiClient = new apiClient();
$apiBuzzTest_buzz = new apiBuzzService($apiBuzzTest_apiClient);
if (!$apiBuzzTest_apiClient->getAccessToken()) {
$apiBuzzTest_apiClient->setAccessToken($apiConfig['oauth_test_token']);
}
}
$this->apiClient = $apiBuzzTest_apiClient;
$this->buzz = $apiBuzzTest_buzz;
}
示例6: refresh_access_token
public function refresh_access_token($email = '')
{
if ($email == '') {
return '';
}
$query = $this->db->query("SELECT refresh_token FROM " . TABLE_GOOGLE . " WHERE email=?", array($email));
if (!isset($query->row['refresh_token'])) {
return '';
}
$client = new apiClient();
$client->setApplicationName(GOOGLE_APPLICATION_NAME);
$client->setClientId(GOOGLE_CLIENT_ID);
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
$client->setRedirectUri(GOOGLE_REDIRECT_URL);
$client->setDeveloperKey(GOOGLE_DEVELOPER_KEY);
$client->refreshToken($query->row['refresh_token']);
$s = $client->getAccessToken();
$a = json_decode($s);
if (isset($a->{'access_token'})) {
return $a->{'access_token'};
}
return '';
}
示例7: PDO
$client->setRedirectUri($config['googleRedirect']);
$client->setApprovalPrompt('auto');
//$oauth2 = new apiOauth2Service($client);
$db = new PDO($config['db'], $config['dbUser'], $config['dbPassword']);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
$stmt = $db->prepare("SELECT `name`, `email`, `token` FROM `users`, `sessions` WHERE `sessions`.`user_id` = `users`.`id` AND `sessions`.`id` = :sessionId AND `users`.`id` = :userId LIMIT 1");
$stmt->execute(array(':userId' => $userId, ':sessionId' => $sessionId));
$user = $stmt->fetch();
if (!$user) {
setcookie('hexauser', '', time() - 60 * 60 * 24 * 365, '/', $_SERVER['HTTP_HOST']);
echo json_encode(array('status' => 'error', 'message' => 'wrong session'));
exit;
}
$token = $user->token;
$client->setAccessToken($token);
$token = $client->getAccessToken();
if (!$token) {
setcookie('hexauser', '', time() - 60 * 60 * 24 * 365, '/', $_SERVER['HTTP_HOST']);
$stmt = $db->prepare("DELETE FROM `sessions` WHERE `id` = :sessionId");
$stmt->execute(array(':sessionId' => $sessionId));
echo json_encode(array('status' => 'error', 'message' => 'session mismatch'));
exit;
}
// Update session id and token
$newSessionId = sha1(uniqid($userId, true) . $user->email . $config['salt']);
$stmt = $db->prepare("UPDATE `sessions` SET `id` = :newSessionId, `token` = :token WHERE `id` = :sessionId");
$stmt->execute(array(':newSessionId' => $newSessionId, ':token' => $token, ':sessionId' => $sessionId));
setcookie('hexauser', $userId . '+' . $newSessionId, time() + 60 * 60 * 24 * 365, '/', $_SERVER['HTTP_HOST']);
// Get highscore
//$stmt = $db->prepare( "SELECT `score` FROM `scoreboards` WHERE `user_id` = :userId ORDER BY `score` DESC LIMIT 1" );
$stmt = $db->prepare("SELECT MAX(`score`) AS `score`, MAX(`level`) AS `level` FROM `scoreboards` WHERE `user_id` = :userId");
示例8: apiClient
require_once '../../src/apiClient.php';
require_once '../../src/contrib/apiUrlshortenerService.php';
// Visit https://code.google.com/apis/console to
// generate your client id, client secret, and redirect uri.
$client = new apiClient();
$client->setClientId('insert_your_oauth2_client_id');
$client->setClientSecret('insert_your_oauth2_client_secret');
$client->setRedirectUri('insert_your_oauth2_redirect_uri');
$service = new apiUrlshortenerService($client);
if (isset($_REQUEST['logout'])) {
unset($_SESSION['access_token']);
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_GET['code'])) {
$client->authenticate();
$_SESSION['access_token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
} else {
$authUrl = $client->createAuthUrl();
}
if ($client->getAccessToken() && isset($_GET['url'])) {
// Start to make API requests.
$url = new Url();
$url->longUrl = $_GET['url'];
$short = $service->url->insert($url);
$_SESSION['access_token'] = $client->getAccessToken();
}
?>
示例9: apiTasksService
// oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri.
// $client->setClientId('insert_your_oauth2_client_id');
// $client->setClientSecret('insert_your_oauth2_client_secret');
// $client->setRedirectUri('insert_your_oauth2_redirect_uri');
// $client->setApplicationName("Tasks_Example_App");
$tasksService = new apiTasksService($client);
if (isset($_REQUEST['logout'])) {
unset($_SESSION['access_token']);
}
if (isset($_SESSION['access_token'])) {
$client->setAccessToken($_SESSION['access_token']);
} else {
$client->setAccessToken($client->authenticate());
$_SESSION['access_token'] = $client->getAccessToken();
}
if (isset($_GET['code'])) {
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
?>
<!doctype html>
<html>
<head>
<title>Tasks API Sample</title>
<link rel='stylesheet' href='http://fonts.googleapis.com/css?family=Droid+Serif|Droid+Sans:regular,bold' />
<link rel='stylesheet' href='css/style.css' />
</head>
<body>
<div id='container'>
示例10: gplus_init_auth
function gplus_init_auth()
{
gplus_load();
$client = new apiClient();
$oauth2 = new apiOauth2Service($client);
if (isset($_GET['code'])) {
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if ($client->getAccessToken()) {
$user = $oauth2->userinfo->get();
$_SESSION['token'] = $client->getAccessToken();
}
if (isset($user) && isset($_GET['code'])) {
$_SESSION['gplusdata'] = $user;
$_SESSION['gplus']['idm'] = $user['id'];
$_SESSION['gplus']['pic'] = !empty($user['picture']) ? $user['picture'] : '';
redirectexit('action=gplus;auth=done');
}
}
示例11: apiClient
<?php
session_start();
require_once "../src/apiClient.php";
$client = new apiClient();
$client->discover('plus');
$client->setScopes(array('https://www.googleapis.com/auth/plus.me'));
if (isset($_GET['logout'])) {
unset($_SESSION['token']);
}
if (isset($_GET['code'])) {
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
$ret = apiBatch::execute($client->plus->activities->list(array('userId' => 'me', 'collection' => 'public'), 'listActivities'), $client->plus->people->get(array('userId' => 'me'), 'getPerson'));
print "<pre>" . print_r($ret, true) . "</pre>";
} else {
$client->authenticate();
}
示例12: index
public function index()
{
session_start();
$client = new apiClient();
$redirectUri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$client->setApplicationName('PHP, YouTube, OAuth2, and CodeIgniter Example');
$client->setClientId(CLIENT_ID);
$client->setClientSecret(CLIENT_SECRET);
$client->setRedirectUri($redirectUri);
$client->setDeveloperKey(DEVELOPER_KEY);
new apiPlusService($client);
// Sets the OAuth2 scope.
$this->load->library('youtube', array('apikey' => YOUTUBE_API_KEY));
// This example doesn't require authentication:
// header("Content-type: text/plain");
// echo "Here is the output:\n";
// echo $this->youtube->getKeywordVideoFeed('pac man');
if (isset($_GET['code'])) {
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
header("Location: {$redirectUri}");
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if (!$client->getAccessToken()) {
$authUrl = $client->createAuthUrl();
echo "<a class='login' href='{$authUrl}'>Connect Me!</a>";
} else {
// The access token may have been updated lazily.
$_SESSION['token'] = $client->getAccessToken();
header("Content-type: text/plain");
$accessToken = json_decode($_SESSION['token'])->access_token;
echo "Here is the output:\n";
echo $this->youtube->getUserUploads('default', array('access_token' => $accessToken, 'prettyprint' => 'true'));
}
}
示例13: __destruct
public function __destruct()
{
global $apiConfig;
$apiConfig['oauth_test_token'] = self::$client->getAccessToken();
}
示例14: apiHttpRequest
font-weight:bolder;
}
strong{
font-weight:bolder;
}
img{
display:none;
}
ul{
font-style: italic;
}
</style>
</head>
<body>
HTML;
if ($client->getAccessToken()) {
$req = new apiHttpRequest("http://www.google.com/reader/api/0/stream/contents/?xt=user/-/state/com.google/read&n=50");
$val = $client->getIo()->authenticatedRequest($req);
$response = json_decode($val->getResponseBody(), true);
foreach ($response['items'] as $item) {
$html .= '<h2>' . $item['title'] . '</h2>' . "\n";
$html .= '<p class="info">作者:' . @$item['author'] . ' 发表时间:' . date('Y-m-d H:i:s', $item['published'] + 8 * 3600) . ' </p>' . "\n";
if (isset($item['summary']['content'])) {
$content = $item['summary']['content'];
} else {
@($content = $item['content']['content']);
}
$html .= '<div class="entry">' . $content . '</div><mbp:pagebreak />' . "\n";
}
}
$html .= <<<HTML
示例15: actionSyncActionsToGoogleCalendar
public function actionSyncActionsToGoogleCalendar()
{
$model = Yii::app()->params->profile;
if (isset($_POST['ProfileChild'])) {
foreach (array_keys($model->attributes) as $field) {
if (isset($_POST['ProfileChild'][$field])) {
$model->{$field} = $_POST['ProfileChild'][$field];
}
}
if ($model->syncGoogleCalendarId && isset($_SESSION['token'])) {
$token = json_decode($_SESSION['token'], true);
$model->syncGoogleCalendarRefreshToken = $token['refresh_token'];
// used for accessing this google calendar at a later time
$model->syncGoogleCalendarAccessToken = $_SESSION['token'];
}
$model->update();
}
$admin = Yii::app()->params->admin;
$googleIntegration = $admin->googleIntegration;
// if google integration is activated let user choose if they want to link this calendar to a google calendar
if ($googleIntegration) {
$timezone = date_default_timezone_get();
require_once "protected/extensions/google-api-php-client/src/apiClient.php";
require_once "protected/extensions/google-api-php-client/src/contrib/apiCalendarService.php";
date_default_timezone_set($timezone);
$client = new apiClient();
$syncGoogleCalendarName = null;
// name of the Google Calendar that current user's actions are being synced to if it has been set
if (isset($_GET['unlinkGoogleCalendar'])) {
// user changed thier mind about linking their google calendar
unset($_SESSION['token']);
$model->syncGoogleCalendarId = null;
$model->syncGoogleCalendarRefreshToken = null;
// used for accessing this google calendar at a later time
$model->syncGoogleCalendarAccessToken = null;
$model->update();
$googleCalendarList = null;
$client->setApplicationName("Google Calendar Integration");
// Visit https://code.google.com/apis/console?api=calendar to generate your
// client id, client secret, and to register your redirect uri.
$client->setClientId($admin->googleClientId);
$client->setClientSecret($admin->googleClientSecret);
$client->setRedirectUri((@$_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $this->createUrl(''));
$client->setDeveloperKey($admin->googleAPIKey);
$client->setAccessType('offline');
$googleCalendar = new apiCalendarService($client);
if (isset($_GET['code'])) {
// returning from google with access token
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
header('Location: ' . (@$_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
$calList = $googleCalendar->calendarList->listCalendarList();
$googleCalendarList = array();
foreach ($calList['items'] as $cal) {
$googleCalendarList[$cal['id']] = $cal['summary'];
}
} else {
$googleCalendarList = null;
}
} else {
if ($model->syncGoogleCalendarRefreshToken) {
$client->setClientId($admin->googleClientId);
$client->setClientSecret($admin->googleClientSecret);
$client->setDeveloperKey($admin->googleAPIKey);
$client->setAccessToken($model->syncGoogleCalendarAccessToken);
$googleCalendar = new apiCalendarService($client);
// check if the access token needs to be refreshed
// note that the google library automatically refreshes the access token if we need a new one,
// we just need to check if this happend by calling a google api function that requires authorization,
// and, if the access token has changed, save this new access token
$testCal = $googleCalendar->calendars->get($model->syncGoogleCalendarId);
if ($model->syncGoogleCalendarAccessToken != $client->getAccessToken()) {
$model->syncGoogleCalendarAccessToken = $client->getAccessToken();
$model->update();
}
$calendar = $googleCalendar->calendars->get($model->syncGoogleCalendarId);
$syncGoogleCalendarName = $calendar['summary'];
$calList = $googleCalendar->calendarList->listCalendarList();
$googleCalendarList = array();
foreach ($calList['items'] as $cal) {
$googleCalendarList[$cal['id']] = $cal['summary'];
}
} else {
$client->setApplicationName("Google Calendar Integration");
// Visit https://code.google.com/apis/console?api=calendar to generate your
// client id, client secret, and to register your redirect uri.
$client->setClientId($admin->googleClientId);
$client->setClientSecret($admin->googleClientSecret);
$client->setRedirectUri((@$_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $this->createUrl(''));
$client->setDeveloperKey($admin->googleAPIKey);
$client->setAccessType('offline');
$googleCalendar = new apiCalendarService($client);
if (isset($_GET['code'])) {
// returning from google with access token
$client->authenticate();
$_SESSION['token'] = $client->getAccessToken();
header('Location: ' . (@$_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
//.........这里部分代码省略.........