Beispiel #1
0
 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());
 }
Beispiel #2
0
  Boilerplate auth management - see
  user-example.php for details.
 ************************************************/
if (isset($_REQUEST['logout'])) {
    unset($_SESSION['access_token']);
}
if (isset($_GET['code'])) {
    $client->authenticate($_GET['code']);
    $_SESSION['access_token'] = $client->getAccessToken();
    $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
    header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
    $client->setAccessToken($_SESSION['access_token']);
} else {
    $authUrl = $client->createAuthUrl();
}
/************************************************
  If we're signed in, retrieve channels from YouTube
  and a list of files from Drive.
 ************************************************/
if ($client->getAccessToken()) {
    $_SESSION['access_token'] = $client->getAccessToken();
    $dr_results = $dr_service->files->listFiles(array('maxResults' => 10));
    $yt_channels = $yt_service->channels->listChannels('contentDetails', array("mine" => true));
    $likePlaylist = $yt_channels[0]->contentDetails->relatedPlaylists->likes;
    $yt_results = $yt_service->playlistItems->listPlaylistItems("snippet", array("playlistId" => $likePlaylist));
}
echo pageHeader("User Query - Multiple APIs");
if ($client_id == '<YOUR_CLIENT_ID>' || $client_secret == '<YOUR_CLIENT_SECRET>' || $redirect_uri == '<YOUR_REDIRECT_URI>') {
    echo missingClientSecretsWarning();