本文整理汇总了PHP中apiClient::setAccessToken方法的典型用法代码示例。如果您正苦于以下问题:PHP apiClient::setAccessToken方法的具体用法?PHP apiClient::setAccessToken怎么用?PHP apiClient::setAccessToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apiClient
的用法示例。
在下文中一共展示了apiClient::setAccessToken方法的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: __construct
public function __construct()
{
parent::__construct();
if (!BaseTest::$client) {
global $apiConfig;
$apiConfig['ioFileCache_directory'] = '/tmp/google-api-php-client/tests';
BaseTest::$client = new apiClient();
if (!BaseTest::$client->getAccessToken()) {
BaseTest::$client->setAccessToken($apiConfig['oauth_test_token']);
}
}
}
示例4: __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);
$apiBuzzTest_apiClient->setAccessToken($apiConfig['oauth_test_token']);
}
$this->apiClient = $apiBuzzTest_apiClient;
$this->buzz = $apiBuzzTest_buzz;
}
示例5: getServiceClient
public static function getServiceClient()
{
if (!self::isServiceConfigured()) {
return false;
}
$config = self::getConfig();
$client = new apiClient(array("ioFileCache_directory" => PIMCORE_CACHE_DIRECTORY));
$client->setApplicationName("pimcore CMF");
$key = file_get_contents(self::getPrivateKeyPath());
$client->setAssertionCredentials(new apiAssertionCredentials($config->email, array('https://www.googleapis.com/auth/analytics.readonly', "https://www.google.com/webmasters/tools/feeds/"), $key));
$client->setClientId($config->client_id);
// token cache
$tokenFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/google-api.token";
if (file_exists($tokenFile)) {
$tokenData = file_get_contents($tokenFile);
$tokenInfo = Zend_Json::decode($tokenData);
if ($tokenInfo["created"] + $tokenInfo["expires_in"] > time() - 900) {
$token = $tokenData;
}
}
if (!$token) {
$client->getAuth()->refreshTokenWithAssertion();
$token = $client->getAuth()->getAccessToken();
file_put_contents($tokenFile, $token);
}
$client->setAccessToken($token);
return $client;
}
示例6: __construct
/**
* Constructor and Login
* @param $buy
* @return Oara_Network_Publisher_Buy_Api
*/
public function __construct($credentials)
{
$client = new apiClient();
$client->setApplicationName("AffJet");
$client->setClientId($credentials['clientId']);
$client->setClientSecret($credentials['clientSecret']);
$client->setAccessToken($credentials['oauth2']);
$client->setAccessType('offline');
$this->_client = $client;
$this->_gan = new apiGanService($client);
}
示例7: BuildService
/**
* Build a Drive service object for interacting with the Google Drive API.
*
* @return apiDriveService service object
*/
function BuildService($credentials)
{
$client = new apiClient();
// return data from API calls as PHP objects instead of arrays
$client->setUseObjects(true);
$client->setAccessToken($credentials->toJson());
// set clientId and clientSecret in case token is expired
// and refresh is needed
$client->setClientId($credentials->clientId);
$client->setClientSecret($credentials->clientSecret);
return new apiDriveService($client);
}
示例8: 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();
}
示例9: __construct
public function __construct() {
global $apiConfig, $apiClient, $taskService;
parent::__construct();
if (! $apiClient || ! $taskService) {
$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();
$taskService = new apiTasksService($apiClient);
$apiClient->setAccessToken($apiConfig['oauth_test_token']);
}
$this->apiClient = $apiClient;
$this->taskService = $taskService;
}
示例10: 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'));
}
}
示例11: testUnauthenticatedStream
/**
* @depends testGetPublicStream
*/
public function testUnauthenticatedStream()
{
global $apiConfig;
// test unauthenticated public stream fetching
$apiConfig['authClass'] = 'apiAuthNone';
$apiClient = new apiClient();
$buzz = new apiBuzzService($apiClient);
$apiClient->setAccessToken($apiConfig['oauth_test_token']);
// fetch the unauthenticated, public activity streamn
$activities = $buzz->listActivities('@public', $apiConfig['oauth_test_user']);
// and evaluate it
$this->evaluateActivitiesStream($activities);
// restore the default Auth class & clean up
$apiConfig['authClass'] = 'apiOAuth';
unset($buzz);
unset($apiClient);
unset($activities);
}
示例12: apiClient
$client = new apiClient();
// Visit https://code.google.com/apis/console to generate your
// 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' />
示例13: getGoogleCalendar
public function getGoogleCalendar()
{
// Google Calendar Libraries
$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);
$admin = Yii::app()->params->admin;
if ($admin->googleIntegration) {
$client = new apiClient();
$client->setClientId($admin->googleClientId);
$client->setClientSecret($admin->googleClientSecret);
$client->setDeveloperKey($admin->googleAPIKey);
$client->setAccessToken($this->googleAccessToken);
$service = 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
$googleCalendar = $service->calendars->get($this->googleCalendarId);
if ($this->googleAccessToken != $client->getAccessToken()) {
$this->googleAccessToken = $client->getAccessToken();
$this->update();
}
return $service;
}
return null;
}
示例14: deleteGoogleCalendarEvent
public function deleteGoogleCalendarEvent($action)
{
try {
// catch google exceptions so the whole app doesn't crash if google has a problem syncing
$admin = Yii::app()->params->admin;
if ($admin->googleIntegration) {
if (isset($this->syncGoogleCalendarId) && $this->syncGoogleCalendarId) {
// Google Calendar Libraries
$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();
$client->setClientId($admin->googleClientId);
$client->setClientSecret($admin->googleClientSecret);
$client->setDeveloperKey($admin->googleAPIKey);
$client->setAccessToken($this->syncGoogleCalendarAccessToken);
$client->setUseObjects(true);
// return objects instead of arrays
$googleCalendar = new apiCalendarService($client);
$googleCalendar->events->delete($this->syncGoogleCalendarId, $action->syncGoogleCalendarEventId);
}
}
} catch (Exception $e) {
}
}
示例15: GetUserInfo
/**
* Retrieve user profile information from Google's UserInfo service.
*
* @param OauthCredentials $credentials Object representation of OAuth creds
* @return Userinfo User profile information
*/
function GetUserInfo($credentials)
{
$client = new apiClient();
$client->setUseObjects(true);
/*
* Set clientId and clientSecret in case token is expired.
* and refresh is needed
*/
$client->setClientId($credentials->clientId);
$client->setClientSecret($credentials->clientSecret);
$client->setAccessToken($credentials->toJson());
$userInfoService = new apiOauth2Service($client);
$userInfo = $userInfoService->userinfo->get();
return $userInfo;
}