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()); }
include_once "templates/base.php"; session_start(); require_once realpath(dirname(__FILE__) . '/../autoload.php'); /************************************************ ATTENTION: Fill in these values! Make sure the redirect URI is to this page, e.g: http://localhost:8080/user-example.php ************************************************/ $client_id = '<YOUR_CLIENT_ID>'; $client_secret = '<YOUR_CLIENT_SECRET>'; $redirect_uri = '<YOUR_REDIRECT_URI>'; $client = new Postman_Google_Client(); $client->setClientId($client_id); $client->setClientSecret($client_secret); $client->setRedirectUri($redirect_uri); $client->setScopes('email'); /************************************************ 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']); } /************************************************ If we have a code back from the OAuth 2.0 flow, we need to exchange that with the authenticate() function. We store the resultant access token bundle in the session, and redirect to ourself. ************************************************/ if (isset($_GET['code'])) { $client->authenticate($_GET['code']);
/* * Copyright 2011 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ require_once dirname(__FILE__) . '/../autoload.php'; $client = new Postman_Google_Client(); $client->setScopes(array("https://www.googleapis.com/auth/plus.me", "https://www.googleapis.com/auth/urlshortener", "https://www.googleapis.com/auth/tasks", "https://www.googleapis.com/auth/adsense", "https://www.googleapis.com/auth/youtube")); $client->setRedirectUri("urn:ietf:wg:oauth:2.0:oob"); // 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(""); $client->setClientSecret(""); $authUrl = $client->createAuthUrl(); `open '{$authUrl}'`; echo "\nPlease enter the auth code:\n"; $authCode = trim(fgets(STDIN)); $accessToken = $client->authenticate($authCode); echo "\n", 'Add the following to BaseTest.php as the $token value:', "\n\n"; echo $accessToken, "\n\n";