public function setAssertionCredentials(Google_Auth_AssertionCredentials $creds)
$this->getAuth()->setAssertionCredentials($creds);
* Set the scopes to be requested. Must be called before createAuthUrl().
* Will remove any previously configured scopes.
* @param array $scopes, ie: array('https://www.googleapis.com/auth/plus.login',
* 'https://www.googleapis.com/auth/moderator')
public function setScopes($scopes)
$this->requestedScopes = array();
$this->addScope($scopes);
* This functions adds a scope to be requested as part of the OAuth2.0 flow.
* Will append any scopes not previously requested to the scope parameter.
* A single string will be treated as a scope to request. An array of strings
* @param $scope_or_scopes string|array e.g. "profile"
public function addScope($scope_or_scopes)
if (is_string($scope_or_scopes) && !in_array($scope_or_scopes, $this->requestedScopes)) {
$this->requestedScopes[] = $scope_or_scopes;
} else if (is_array($scope_or_scopes)) {
foreach ($scope_or_scopes as $scope) {
* Returns the list of scopes requested by the client
* @return array the list of scopes
public function getScopes()
return $this->requestedScopes;
* Declare whether batch calls should be used. This may increase throughput
* by making multiple requests in one connection.
* @param boolean $useBatch True if the batch support should
* be enabled. Defaults to False.
public function setUseBatch($useBatch)
// This is actually an alias for setDefer.
$this->setDefer($useBatch);
* Declare whether making API calls should make the call immediately, or
* return a request which can be called with ->execute();
* @param boolean $defer True if calls should not be executed right away.
public function setDefer($defer)
$this->deferExecution = $defer;
* Helper method to execute deferred HTTP requests.
* @param $request Google_Http_Request|Google_Http_Batch
* @throws Google_Exception
* @return object of the type of the expected class or array.
public function execute($request)
if ($request instanceof UDP_Google_Http_Request) {
$this->getApplicationName()
. " " . self::USER_AGENT_SUFFIX
. $this->getLibraryVersion()
if (!$this->getClassConfig("UDP_Google_Http_Request", "disable_gzip")) {
$request->maybeMoveParametersToBody();
return UDP_Google_Http_REST::execute($this, $request);
} else if ($request instanceof Google_Http_Batch) {
return $request->execute();
throw new Google_Exception("Do not know how to execute this type of object.");
* Whether or not to return raw requests
public function shouldDefer()
return $this->deferExecution;
* @return Google_Auth_Abstract Authentication implementation
public function getAuth()
if (!isset($this->auth)) {
$class = $this->config->getAuthClass();
$this->auth = new $class($this);
* @return UDP_Google_IO_Abstract IO implementation
$class = $this->config->getIoClass();
$this->io = new $class($this);
* @return Google_Cache_Abstract Cache implementation
public function getCache()
if (!isset($this->cache)) {
$class = $this->config->getCacheClass();
$this->cache = new $class($this);
* @return Google_Logger_Abstract Logger implementation
public function getLogger()
if (!isset($this->logger)) {
$class = $this->config->getLoggerClass();
$this->logger = new $class($this);
* Retrieve custom configuration for a specific class.
* @param $class string|object - class or instance of class to retrieve
* @param $key string optional - key to retrieve
public function getClassConfig($class, $key = null)
if (!is_string($class)) {
$class = get_class($class);
return $this->config->getClassConfig($class, $key);
* Set configuration specific to a given class.
* $config->setClassConfig('Google_Cache_File',
* array('directory' => '/tmp/cache'));
* @param $class string|object - The class name for the configuration
* @param $config string key or an array of configuration values
* @param $value string optional - if $config is a key, the value
public function setClassConfig($class, $config, $value = null)
if (!is_string($class)) {
$class = get_class($class);
$this->config->setClassConfig($class, $config, $value);
* @return string the base URL to use for calls to the APIs
public function getBasePath()
return $this->config->getBasePath();
* @return string the name of the application
public function getApplicationName()
return $this->config->getApplicationName();
* Are we running in Google AppEngine?
public function isAppEngine()
return (isset($_SERVER['SERVER_SOFTWARE']) &&
strpos($_SERVER['SERVER_SOFTWARE'], 'Google App Engine') !== false);