当前位置: 首页>>代码示例>>PHP>>正文


PHP Google_Client::setState方法代码示例

本文整理汇总了PHP中Google_Client::setState方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_Client::setState方法的具体用法?PHP Google_Client::setState怎么用?PHP Google_Client::setState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Google_Client的用法示例。


在下文中一共展示了Google_Client::setState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionToken

 public function actionToken()
 {
     //$this->checkAccess("token");
     $client = new \Google_Client();
     $client->setClientId(Yii::$app->params['OAUTH2_CLIENT_ID']);
     $client->setClientSecret(Yii::$app->params['OAUTH2_CLIENT_SECRET']);
     $client->setScopes('https://www.googleapis.com/auth/youtube');
     //$redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], FILTER_SANITIZE_URL);
     $client->setRedirectUri(Yii::$app->params['redirectVideo']);
     if (Yii::$app->request->get('code')) {
         if (strval(Yii::$app->session->get('state')) !== strval(Yii::$app->request->get('state'))) {
             die('The session state did not match.');
         }
         $client->authenticate(Yii::$app->request->get('code'));
         if ($client->getAccessToken()) {
             $token = $this->getToken();
             $token->load(json_decode($client->getAccessToken(), true), "");
             $token->save();
             return ["token_saved" => $token];
         }
         return ["token_not_saved_code" => Yii::$app->request->get('code')];
     }
     if (!$client->getAccessToken()) {
         // If the user hasn't authorized the app, initiate the OAuth flow
         //$state = mt_rand();
         $client->setState(Yii::$app->params['stateVideo']);
         $client->setAccessType("offline");
         $client->setApprovalPrompt("force");
         Yii::$app->session->set('state', Yii::$app->params['stateVideo']);
         $authUrl = $client->createAuthUrl();
         return ["link" => $authUrl];
     }
 }
开发者ID:pylypen,项目名称:api-side,代码行数:33,代码来源:VideoController.php

示例2: fclose

            $uploadStatus = $media->nextChunk($insertResponse, $chunk);
        }
        fclose($handle);
        $htmlBody .= "<h3>Video Uploaded</h3><ul>";
        $htmlBody .= sprintf('<li>%s (%s)</li>', $uploadStatus['snippet']['title'], $uploadStatus['id']);
        $htmlBody .= '</ul>';
    } catch (Google_ServiceException $e) {
        $htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
    } catch (Google_Exception $e) {
        $htmlBody .= sprintf('<p>An client error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
    }
    $_SESSION['token'] = $client->getAccessToken();
} else {
    // If the user hasn't authorized the app, initiate the OAuth flow
    $state = mt_rand();
    $client->setState($state);
    $_SESSION['state'] = $state;
    $authUrl = $client->createAuthUrl();
    $htmlBody = <<<END
  <h3>Authorization Required</h3>
  <p>You need to <a href="{$authUrl}">authorize access</a> before proceeding.<p>
END;
}
?>

<!doctype html>
<html>
<head>
<title>Video Uploaded</title>
</head>
<body>
开发者ID:kenkaq6312,项目名称:youtube-api-samples,代码行数:31,代码来源:resumable_upload.php

示例3: getRedirectUri

 /**
  * This method is used to process the first part of authentication workflow, before redirect
  *
  * @return array Array with status and redirect URI
  */
 public function getRedirectUri()
 {
     $ngConnectINI = eZINI::instance('ngconnect.ini');
     $http = eZHTTPTool::instance();
     $clientID = trim($ngConnectINI->variable('LoginMethod_google', 'GoogleClientID'));
     if (empty($clientID)) {
         return array('status' => 'error', 'message' => 'Google client ID undefined.');
     }
     $callbackUri = self::CALLBACK_URI_PART;
     $loginWindowType = trim($ngConnectINI->variable('ngconnect', 'LoginWindowType'));
     if ($loginWindowType == 'popup') {
         $callbackUri = '/layout/set/ngconnect' . self::CALLBACK_URI_PART;
     }
     eZURI::transformURI($callbackUri, false, 'full');
     $state = md5(session_id() . (string) time());
     $http->setSessionVariable('NGConnectOAuthState', $state);
     $scope = self::SCOPE;
     $userScope = trim($ngConnectINI->variable('LoginMethod_google', 'Scope'));
     if (!empty($userScope)) {
         $scope = $userScope . ' ' . $scope;
     }
     $client = new Google_Client();
     $client->setApplicationName(trim($ngConnectINI->variable('LoginMethod_google', 'MethodName')));
     $client->setScopes($scope);
     $client->setClientId($clientID);
     $client->setRedirectUri($callbackUri);
     $client->setState($state);
     return array('status' => 'success', 'redirect_uri' => $client->createAuthUrl());
 }
开发者ID:netgen,项目名称:ngconnect,代码行数:34,代码来源:ngconnectauthgoogle.php

示例4: getClient

function getClient()
{
    $config = (include __DIR__ . '/ini.php');
    $client = new Google_Client();
    $client->setApplicationName("Webkameleon");
    $client->setClientId($config['oauth2_client_id']);
    $client->setClientSecret($config['oauth2_client_secret']);
    $client->setRedirectUri($config['oauth2_redirect_uri']);
    $client->setScopes($config['oauth2_scopes']);
    $client->setState('offline');
    $client->setAccessType('offline');
    $client->setApprovalPrompt('force');
    if (isset($_GET['code'])) {
        $client->authenticate($_GET['code']);
        die($client->getAccessToken());
    } elseif (!isset($config['token'])) {
        Header('Location: ' . $client->createAuthUrl());
    } else {
        $client->setAccessToken($config['token']);
        if ($client->isAccessTokenExpired()) {
            $token = json_decode($config['token'], true);
            $client->refreshToken($token['refresh_token']);
        }
    }
    return $client;
}
开发者ID:podstawski,项目名称:appengine,代码行数:26,代码来源:google.php

示例5: testSettersGetters

 public function testSettersGetters()
 {
     $client = new Google_Client();
     $client->setClientId("client1");
     $client->setClientSecret('client1secret');
     $client->setState('1');
     $client->setApprovalPrompt('force');
     $client->setAccessType('offline');
     $client->setRedirectUri('localhost');
     $client->setApplicationName('me');
     $this->assertEquals('object', gettype($client->getAuth()));
     $this->assertEquals('object', gettype($client->getCache()));
     $this->assertEquals('object', gettype($client->getIo()));
     $client->setAuth(new Google_Auth_Simple($client));
     $client->setAuth(new Google_Auth_OAuth2($client));
     try {
         $client->setAccessToken(null);
         die('Should have thrown an Google_Auth_Exception.');
     } catch (Google_Auth_Exception $e) {
         $this->assertEquals('Could not json decode the token', $e->getMessage());
     }
     $token = json_encode(array('access_token' => 'token'));
     $client->setAccessToken($token);
     $this->assertEquals($token, $client->getAccessToken());
 }
开发者ID:te-koyama,项目名称:openpne,代码行数:25,代码来源:ApiClientTest.php

示例6: getAuthURL

 /**
  * Returns a URL the user can visit to grant us permission to access their feed
  *
  * @return string
  */
 public function getAuthURL()
 {
     $state = mt_rand();
     $this->client->setState($state);
     Session::set($this->stateSessionIdentifier, $state);
     return $this->client->createAuthUrl();
 }
开发者ID:helpfulrobot,项目名称:littlegiant-silverstripe-youtubefeed,代码行数:12,代码来源:YouTubeFeed.php

示例7: createAuthUrl

 /**
  * @param $staff_id
  * @return string
  */
 public function createAuthUrl($staff_id)
 {
     $this->client->setRedirectUri($this->generateRedirectURI());
     $this->client->addScope('https://www.googleapis.com/auth/calendar');
     $this->client->setState(strtr(base64_encode($staff_id), '+/=', '-_,'));
     $this->client->setApprovalPrompt('force');
     $this->client->setAccessType('offline');
     return $this->client->createAuthUrl();
 }
开发者ID:patrickcurl,项目名称:monks,代码行数:13,代码来源:AB_Google.php

示例8: render

 /**
  * Render method
  * @return var $output
  */
 public function render()
 {
     session_start();
     $OAUTH2_CLIENT_ID = $this->arguments['clientid'];
     $OAUTH2_CLIENT_SECRET = $this->arguments['clientsecret'];
     $client = new Google_Client();
     $client->setClientId($OAUTH2_CLIENT_ID);
     $client->setClientSecret($OAUTH2_CLIENT_SECRET);
     $redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], FILTER_SANITIZE_URL);
     $client->setRedirectUri($redirect);
     $youtube = new Google_YoutubeService($client);
     if (isset($_GET['code'])) {
         if (strval($_SESSION['state']) !== strval($_GET['state'])) {
             die('The session state did not match.');
         }
         $client->authenticate();
         $_SESSION['token'] = $client->getAccessToken();
         header('Location: ' . $redirect);
     }
     if (isset($_SESSION['token'])) {
         $client->setAccessToken($_SESSION['token']);
     }
     if ($client->getAccessToken()) {
         try {
             $channelsResponse = $youtube->channels->listChannels('contentDetails', array('mine' => 'true'));
             $output = '';
             foreach ($channelsResponse['items'] as $channel) {
                 $uploadsListId = $channel['contentDetails']['relatedPlaylists']['uploads'];
                 $playlistItemsResponse = $youtube->playlistItems->listPlaylistItems('snippet', array('playlistId' => $uploadsListId, 'maxResults' => 50));
                 $output .= "<h3>Videos in list {$uploadsListId}</h3><ul>";
                 foreach ($playlistItemsResponse['items'] as $playlistItem) {
                     $output .= sprintf('<li>%s (%s)</li>', $playlistItem['snippet']['title'], $playlistItem['snippet']['resourceId']['videoId']);
                 }
                 $output .= '</ul>';
             }
         } catch (Google_ServiceException $e) {
             $output .= sprintf('<p>A service error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
         } catch (Google_Exception $e) {
             $output .= sprintf('<p>An client error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
         }
         $_SESSION['token'] = $client->getAccessToken();
     } else {
         $state = mt_rand();
         $client->setState($state);
         $_SESSION['state'] = $state;
         $authUrl = $client->createAuthUrl();
         $output = '<h3>Authorization Required</h3><p>You need to <a href="' . $authUrl . '">authorize access</a> before proceeding.<p>';
     }
     return $output;
 }
开发者ID:preinboth,项目名称:moox_social,代码行数:54,代码来源:YoutubeViewHelper.php

示例9: getAuthorizationUrl

/** 
* Lets first get an authorization URL to our client, it will forward the client to Google's Concent window
* @param String $emailAddress
* @param String $state
* @return String URL to Google Concent screen
*/
function getAuthorizationUrl($emailAddress, $state)
{
    global $CLIENT_ID, $REDIRECT_URI, $SCOPES;
    $client = new Google_Client();
    $client->setClientId($CLIENT_ID);
    $client->setRedirectUri($REDIRECT_URI);
    $client->setAccessType('offline');
    $client->setApprovalPrompt('auto');
    $client->setState($state);
    $client->setScopes($SCOPES);
    $tmpUrl = parse_url($client->createAuthUrl());
    $query = explode('&', $tmpUrl['query']);
    $query[] = 'user_id=' . urlencode($emailAddress);
    return $tmpUrl['scheme'] . '://' . $tmpUrl['host'] . $tmpUrl['path'] . '?' . implode('&', $query);
}
开发者ID:vongalpha,项目名称:google-drive-sdk-api-php-insert-file-parent-example,代码行数:21,代码来源:functions.php

示例10: getBaseClient

 public static function getBaseClient($state = null)
 {
     if (!self::$_baseClient) {
         $cfg = self::_getApiConfig();
         $client = new Google_Client();
         $client->setApplicationName($cfg['appName']);
         $client->setClientId($cfg['clientId']);
         $client->setClientSecret($cfg['clientSecret']);
         $client->setRedirectUri(self::_getRedirectUrl());
         $client->setAccessType($cfg['accessType']);
         $client->setUseObjects($cfg['useObjects']);
         if ($state) {
             $client->setState($state);
         }
         self::$_baseClient = $client;
     }
     return self::$_baseClient;
 }
开发者ID:Rademade,项目名称:MedOptima,代码行数:18,代码来源:Config.php

示例11: index

 public function index()
 {
     ini_set("display_errors", 1);
     $youtubeClientIdAry = $this->M_Configuration->getConfigurationDetails('youtube_clientId');
     $youtubeClientSecretAry = $this->M_Configuration->getConfigurationDetails('youtube_clientSecret');
     $OAUTH2_CLIENT_ID = $youtubeClientIdAry->configuration_data;
     $OAUTH2_CLIENT_SECRET = $youtubeClientSecretAry->configuration_data;
     if (isset($_GET['code'])) {
         $url = 'https://accounts.google.com/o/oauth2/token';
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_FAILONERROR, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
         $code = $_GET['code'];
         curl_setopt($ch, CURLOPT_POSTFIELDS, 'code=' . $code . '&' . 'client_id=' . $OAUTH2_CLIENT_ID . '&' . 'client_secret=' . $OAUTH2_CLIENT_SECRET . '&' . 'redirect_uri=' . urlencode('http://mystory.buzz/admin/getRefreshToken') . '&' . 'grant_type=' . 'authorization_code');
         $output = curl_exec($ch);
         curl_close($ch);
         echo $output;
         $obj = json_decode($output);
         $token = $obj->{'refresh_token'};
         $insertVal = array('youtube_refreshToken' => $token);
         $result = $this->M_Configuration->saveDetails($insertVal);
         exit;
     }
     $client = new Google_Client();
     $client->setClientId($OAUTH2_CLIENT_ID);
     //$client->setClientSecret($OAUTH2_CLIENT_SECRET);
     //$client->refreshToken('1/ZniNI97r2y14HXQzW15JC-3VeaMCjVFXIbOCFRjVPEUMEudVrK5jSpoR30zcRFq6');
     $client->setScopes('https://gdata.youtube.com');
     $client->setAccessType('offline');
     $client->setApprovalPrompt('force');
     $redirect = filter_var('http://mystory.buzz/admin/getRefreshToken', FILTER_SANITIZE_URL);
     $client->setRedirectUri($redirect);
     // If the user hasn't authorized the app, initiate the OAuth flow
     $state = mt_rand();
     $client->setState($state);
     $_SESSION['state'] = $state;
     $authUrl = $client->createAuthUrl();
     $data['authUrl'] = $authUrl;
     $this->load->view('configuration/v_refreshToken', $data);
 }
开发者ID:glennpeterm,项目名称:MyStoryWeb,代码行数:42,代码来源:getRefreshToken.php

示例12: initialize_oauth

 private function initialize_oauth()
 {
     $redirecturi = new moodle_url(self::REDIRECTURL);
     $returnurl = new moodle_url('/portfolio/add.php');
     $returnurl->param('postcontrol', 1);
     $returnurl->param('id', $this->exporter->get('id'));
     $returnurl->param('sesskey', sesskey());
     $clientid = $this->get_config('clientid');
     $secret = $this->get_config('secret');
     // Setup Google client.
     $this->client = get_google_client();
     $this->client->setClientId($clientid);
     $this->client->setClientSecret($secret);
     $this->client->setScopes(array(Google_Service_Drive::DRIVE_FILE));
     $this->client->setRedirectUri($redirecturi->out(false));
     // URL to be called when redirecting from authentication.
     $this->client->setState($returnurl->out_as_local_url(false));
     // Setup drive upload service.
     $this->service = new Google_Service_Drive($this->client);
 }
开发者ID:evltuma,项目名称:moodle,代码行数:20,代码来源:lib.php

示例13: authAction

 public function authAction()
 {
     $url = Mage::getUrl("adminhtml/googleShoppingApi_oauth/auth");
     // /index.php/admin/googleShoppingApi_oauth/auth/
     $storeId = $this->getRequest()->getParam('store_id');
     $state = $this->getRequest()->getParam('state');
     if ($state) {
         $params = json_decode(base64_decode(urldecode($state)));
         $storeId = $params->store_id;
     } else {
         $state = urlencode(base64_encode(json_encode(array('store_id' => $storeId))));
     }
     $clientId = $this->getConfig()->getConfigData('client_id', $storeId);
     $clientSecret = $this->getConfig()->getConfigData('client_secret', $storeId);
     $adminSession = Mage::getSingleton('admin/session');
     $service = Mage::getModel('googleshoppingapi/googleShopping');
     $client = new Google_Client();
     $client->setApplicationName(Weboffice_GoogleShoppingApi_Model_GoogleShopping::APPNAME);
     $client->setClientId($clientId);
     $client->setClientSecret($clientSecret);
     $client->setRedirectUri($url);
     $client->setScopes('https://www.googleapis.com/auth/content');
     $client->setState($state);
     $accessTokens = $adminSession->getGoogleOAuth2Token();
     if (!is_array($accessTokens)) {
         $accessTokens = array();
     }
     $code = $this->getRequest()->getParam('code');
     if ($code) {
         $accessToken = $client->authenticate($code);
         $accessTokens[$storeId] = $accessToken;
         $adminSession->setGoogleOAuth2Token($accessTokens);
         // unlock flag after successfull authentication
         $flag = $this->_getFlag();
         $flag->unlock();
         $this->_redirect('*/googleShoppingApi_items/index', array('store' => $storeId));
         return $this;
     }
     header('Location: ' . $client->createAuthUrl());
     exit;
 }
开发者ID:shakhawat4g,项目名称:MagentoExtensions,代码行数:41,代码来源:OauthController.php

示例14: array


//.........这里部分代码省略.........
         $calendars_status[4]['actions'] = array(4);
         //5 = delete calendar
         $calendars_actions[5] = array();
         $calendars_actions[5]['text'] = lang('classify');
         $calendars_actions[5]['function'] = 'og.google_calendar_classify';
         tpl_assign('calendars_status', $calendars_status);
         $user_data['id'] = $user->getId();
         $user_data['auth_user'] = $user->getAuthUser();
         $user_data['sync'] = $user->getSync();
         tpl_assign('user', $user_data);
         // Step 3: We have access we can now create our service
         try {
             $service = $this->connect_with_google_calendar($user);
             $calendarList = $service->calendarList->listCalendarList();
             $instalation = explode("/", ROOT_URL);
             $instalation_name = end($instalation);
             $feng_calendar_name = lang('feng calendar', $instalation_name);
             while (true) {
                 foreach ($calendarList->getItems() as $calendarListEntry) {
                     //is feng calendar
                     if ($calendarListEntry->getSummary() == $feng_calendar_name) {
                         continue;
                     }
                     $external_calendars[$calendarListEntry->getId()] = array('original_calendar_id' => $calendarListEntry->getId(), 'title' => $calendarListEntry->getSummary(), 'calendar_status' => 1);
                 }
                 $pageToken = $calendarList->getNextPageToken();
                 if ($pageToken) {
                     $optParams = array('pageToken' => $pageToken);
                     $calendarList = $service->calendarList->listCalendarList($optParams);
                 } else {
                     break;
                 }
             }
         } catch (Exception $e) {
             $service_is_working = false;
         }
         //Calendars status
         $view_calendars = array();
         $calendars = ExternalCalendars::findByExtCalUserId($user->getId(), true);
         foreach ($calendars as $ext_calendar) {
             $view_calendar = array();
             $view_calendar['original_calendar_id'] = $ext_calendar->getOriginalCalendarId();
             $view_calendar['title'] = $ext_calendar->getCalendarName();
             $members = array();
             $member_ids = explode(",", $ext_calendar->getRelatedTo());
             foreach ($member_ids as $member_id) {
                 $members[$member_id] = $member_id;
             }
             if (count($members)) {
                 $view_calendar['members'] = json_encode(array(1 => $members));
             }
             $view_calendar['calendar_id'] = $ext_calendar->getId();
             //deleted on google
             $view_calendar['calendar_status'] = 4;
             if (array_key_exists($ext_calendar->getOriginalCalendarId(), $external_calendars)) {
                 //not in sync
                 $view_calendar['calendar_status'] = 3;
                 if ($ext_calendar->getSync()) {
                     //in sync
                     $view_calendar['calendar_status'] = 2;
                 }
                 unset($external_calendars[$ext_calendar->getOriginalCalendarId()]);
             }
             $view_calendars[$ext_calendar->getOriginalCalendarId()] = $view_calendar;
         }
         $all_calendars = array_merge($external_calendars, $view_calendars);
         ksort($all_calendars);
         tpl_assign('external_calendars', $all_calendars);
         $sync_from_feng = false;
         if ($user->getSync() == 1) {
             $calendar_feng = ExternalCalendars::findFengCalendarByExtCalUserIdValue($user->getId());
             if ($calendar_feng instanceof ExternalCalendar && $calendar_feng->getSync() == 0) {
                 $sync_from_feng = false;
             } else {
                 $sync_from_feng = true;
             }
         }
         if ($sync_from_feng) {
             $sync_from_feng_action = "og.google_calendar_stop_sync_feng_calendar";
             $sync_from_feng_color = "2";
             $sync_from_feng_text = lang('stop sync');
         } else {
             $sync_from_feng_action = "og.google_calendar_start_sync_feng_calendar";
             $sync_from_feng_color = "3";
             $sync_from_feng_text = lang('start sync');
         }
         tpl_assign('sync_from_feng_action', $sync_from_feng_action);
         tpl_assign('sync_from_feng_color', $sync_from_feng_color);
         tpl_assign('sync_from_feng_text', $sync_from_feng_text);
     }
     if (!$user || !$service_is_working) {
         // Step 1:  The user has not authenticated we give them a link to login
         if (!$google_code) {
             $client->setScopes(array('https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile'));
             $client->setState(ROOT_URL . '/index.php?c=external_calendar&a=calendar_sinchronization');
             $authUrl = $client->createAuthUrl();
             tpl_assign('auth_url', $authUrl);
         }
     }
 }
开发者ID:abhinay100,项目名称:feng_app,代码行数:101,代码来源:ExternalCalendarController.class.php

示例15: testSettersGetters

 public function testSettersGetters()
 {
     $client = new Google_Client();
     $client->setClientId("client1");
     $client->setClientSecret('client1secret');
     $client->setState('1');
     $client->setApprovalPrompt('force');
     $client->setAccessType('offline');
     $client->setRedirectUri('localhost');
     $client->setConfig('application_name', 'me');
     $client->setCache($this->getMock('Psr\\Cache\\CacheItemPoolInterface'));
     $this->assertEquals('object', gettype($client->getCache()));
     try {
         $client->setAccessToken(null);
         $this->fail('Should have thrown an Exception.');
     } catch (InvalidArgumentException $e) {
         $this->assertEquals('invalid json token', $e->getMessage());
     }
     $token = array('access_token' => 'token');
     $client->setAccessToken($token);
     $this->assertEquals($token, $client->getAccessToken());
 }
开发者ID:jvidor,项目名称:google-api-php-client,代码行数:22,代码来源:ClientTest.php


注:本文中的Google_Client::setState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。