コード例 #1
0
ファイル: ApiClientTest.php プロジェクト: rapier83/isaebooks
 public function testPrepareService()
 {
     $client = new Postman_Google_Client();
     $client->setScopes(array("scope1", "scope2"));
     $scopes = $client->prepareScopes();
     $this->assertEquals("scope1 scope2", $scopes);
     $client->setScopes(array("", "scope2"));
     $scopes = $client->prepareScopes();
     $this->assertEquals(" scope2", $scopes);
     $client->setScopes("scope2");
     $client->addScope("scope3");
     $client->addScope(array("scope4", "scope5"));
     $scopes = $client->prepareScopes();
     $this->assertEquals("scope2 scope3 scope4 scope5", $scopes);
     $client->setClientId('test1');
     $client->setRedirectUri('http://localhost/');
     $client->setScopes(array("http://test.com", "scope2"));
     $scopes = $client->prepareScopes();
     $this->assertEquals("http://test.com scope2", $scopes);
     $this->assertEquals('' . 'https://accounts.google.com/o/oauth2/auth' . '?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%2F' . '&client_id=test1' . '&scope=http%3A%2F%2Ftest.com+scope2&access_type=online' . '&approval_prompt=auto', $client->createAuthUrl());
     // This should not trigger a request.
     $client->setDefer(true);
     $dr_service = new Postman_Google_Service_Drive($client);
     $this->assertInstanceOf('Postman_Google_Http_Request', $dr_service->files->listFiles());
 }
コード例 #2
0
 /**
  * (non-PHPdoc)
  *
  * @see PostmanZendModuleTransport::createZendMailTransport()
  */
 public function createZendMailTransport($fakeHostname, $fakeConfig)
 {
     if (PostmanOptions::AUTHENTICATION_TYPE_OAUTH2 == $this->getAuthenticationType()) {
         $config = PostmanOAuth2ConfigurationFactory::createConfig($this);
     } else {
         $config = PostmanBasicAuthConfigurationFactory::createConfig($this);
     }
     // Google's autoloader will try and load this so we list it first
     require_once 'PostmanGmailApiModuleZendMailTransport.php';
     // Gmail Client includes
     require_once 'google-api-php-client-1.1.2/src/Google/Client.php';
     require_once 'google-api-php-client-1.1.2/src/Google/Service/Gmail.php';
     // build the Gmail Client
     $authToken = PostmanOAuthToken::getInstance();
     $client = new Postman_Google_Client();
     $client->setClientId($this->options->getClientId());
     $client->setClientSecret($this->options->getClientSecret());
     $client->setRedirectUri('');
     // rebuild the google access token
     $token = new stdClass();
     $token->access_token = $authToken->getAccessToken();
     $token->refresh_token = $authToken->getRefreshToken();
     $token->token_type = 'Bearer';
     $token->expires_in = 3600;
     $token->id_token = null;
     $token->created = 0;
     $client->setAccessToken(json_encode($token));
     // We only need permissions to compose and send emails
     $client->addScope("https://www.googleapis.com/auth/gmail.compose");
     $service = new Postman_Google_Service_Gmail($client);
     $config[PostmanGmailApiModuleZendMailTransport::SERVICE_OPTION] = $service;
     return new PostmanGmailApiModuleZendMailTransport(self::HOST, $config);
 }
コード例 #3
0
ファイル: multi-api.php プロジェクト: rapier83/isaebooks
 ************************************************/
$client_id = '<YOUR_CLIENT_ID>';
$client_secret = '<YOUR_CLIENT_SECRET>';
$redirect_uri = '<YOUR_REDIRECT_URI>';
/************************************************
  Make an API request on behalf of a user. In
  this case we need to have a valid OAuth 2.0
  token for the user, so we need to send them
  through a login flow. To do this we need some
  information from our API console project.
 ************************************************/
$client = new Postman_Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope("https://www.googleapis.com/auth/drive");
$client->addScope("https://www.googleapis.com/auth/youtube");
/************************************************
  We are going to create both YouTube and Drive
  services, and query both.
 ************************************************/
$yt_service = new Postman_Google_Service_YouTube($client);
$dr_service = new Postman_Google_Service_Drive($client);
/************************************************
  Boilerplate auth management - see
  user-example.php for details.
 ************************************************/
if (isset($_REQUEST['logout'])) {
    unset($_SESSION['access_token']);
}
if (isset($_GET['code'])) {
コード例 #4
0
 /**
  * This is the only place where the Google library is loaded
  *
  * @see PostmanTransport::createZendMailTransport()
  */
 public function createZendMailTransport($hostname, $config)
 {
     // This is where the ZendMail special transport is loaded
     require_once 'PostmanGmailApiModuleZendMailTransport.php';
     // This is the only place where the Google library is loaded
     require_once 'google-api-php-client-1.1.2/src/Google/Client.php';
     require_once 'google-api-php-client-1.1.2/src/Google/Service/Gmail.php';
     // build the Gmail Client
     $options = PostmanOptions::getInstance();
     $authToken = PostmanOAuthToken::getInstance();
     $client = new Postman_Google_Client();
     $client->setClientId($options->getClientId());
     $client->setClientSecret($options->getClientSecret());
     $client->setRedirectUri('');
     // rebuild the google access token
     $token = new stdClass();
     $token->access_token = $authToken->getAccessToken();
     $token->refresh_token = $authToken->getRefreshToken();
     $token->token_type = 'Bearer';
     $token->expires_in = 3600;
     $token->id_token = null;
     $token->created = 0;
     $client->setAccessToken(json_encode($token));
     // We only need permissions to compose and send emails
     $client->addScope("https://www.googleapis.com/auth/gmail.compose");
     $service = new Postman_Google_Service_Gmail($client);
     $config[PostmanGmailApiModuleZendMailTransport::SERVICE_OPTION] = $service;
     return new PostmanGmailApiModuleZendMailTransport($hostname, $config);
 }
コード例 #5
0
ファイル: user-example.php プロジェクト: rapier83/isaebooks
 ************************************************/
$client_id = '<YOUR_CLIENT_ID>';
$client_secret = '<YOUR_CLIENT_SECRET>';
$redirect_uri = '<YOUR_REDIRECT_URI>';
/************************************************
  Make an API request on behalf of a user. In
  this case we need to have a valid OAuth 2.0
  token for the user, so we need to send them
  through a login flow. To do this we need some
  information from our API console project.
 ************************************************/
$client = new Postman_Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope("https://www.googleapis.com/auth/urlshortener");
/************************************************
  When we create the service here, we pass the
  client to it. The client then queries the service
  for the required scopes, and uses that when
  generating the authentication URL later.
 ************************************************/
$service = new Postman_Google_Service_Urlshortener($client);
/************************************************
  If we're logging out we just need to clear our
  local access token in this case
 ************************************************/
if (isset($_REQUEST['logout'])) {
    unset($_SESSION['access_token']);
}
/************************************************