├── static
└── Credentials.png
├── test
├── README
├── phpunit.xml
├── general
│ ├── ApiModelTest.php
│ ├── testdata
│ │ └── test_public_key.pem
│ ├── ApiBatchRequestTest.php
│ ├── OAuthHelper.php
│ ├── GeneralTests.php
│ ├── CacheTest.php
│ └── ApiOAuth2Test.php
├── tasks
│ ├── AllTasksTests.php
│ └── TasksTest.php
├── pagespeed
│ ├── AllPageSpeedTests.php
│ └── PageSpeedTest.php
├── urlshortener
│ ├── AllUrlShortenerTests.php
│ └── UrlShortenerTests.php
├── BaseTest.php
├── AllTests.php
└── plus
│ └── PlusTest.php
├── NOTICE
├── examples
├── webfonts
│ └── simple.php
├── adexchangebuyer
│ ├── style.css
│ ├── examples
│ │ ├── GetAllAccounts.php
│ │ ├── GetDirectDeals.php
│ │ ├── UpdateAccount.php
│ │ └── GetCreative.php
│ └── htmlHelper.php
├── translate
│ └── simple.php
├── books
│ ├── simple.php
│ ├── books_browser.css
│ └── interface.html
├── shopping
│ └── simple.php
├── adsensehost
│ ├── examples
│ │ ├── StartAssociationSession.php
│ │ ├── VerifyAssociationSession.php
│ │ ├── AddUrlChannelToHost.php
│ │ ├── DeleteUrlChannelOnHost.php
│ │ ├── AddCustomChannelToHost.php
│ │ ├── DeleteCustomChannelOnHost.php
│ │ ├── DeleteAdUnitOnPublisher.php
│ │ ├── UpdateCustomChannelOnHost.php
│ │ ├── GenerateReportForHost.php
│ │ ├── GetAccountDataForExistingPublisher.php
│ │ ├── UpdateAdUnitOnPublisher.php
│ │ ├── GetAllUrlChannelsForHost.php
│ │ ├── GenerateReportForPublisher.php
│ │ ├── GetAllAdClientsForHost.php
│ │ ├── GetAllAdUnitsForPublisher.php
│ │ ├── GetAllCustomChannelsForHost.php
│ │ ├── GetAllAdClientsForPublisher.php
│ │ └── AddAdUnitToPublisher.php
│ ├── style.css
│ └── BaseExample.php
├── calendar
│ └── simple.php
├── siteVerification
│ └── simple.php
├── adexchangeseller
│ ├── examples
│ │ ├── GenerateSavedReport.php
│ │ ├── GetAllAlerts.php
│ │ ├── GetAllMetrics.php
│ │ ├── GetAllDimensions.php
│ │ ├── GetAllPreferredDeals.php
│ │ ├── GenerateReport.php
│ │ ├── GetAllUrlChannels.php
│ │ ├── GetAllAdUnits.php
│ │ ├── GetAllSavedReports.php
│ │ ├── GetAllAdClients.php
│ │ └── GetAllAdUnitsForCustomChannel.php
│ ├── style.css
│ └── BaseExample.php
├── adsense
│ ├── examples
│ │ ├── GenerateSavedReport.php
│ │ ├── GetAllAlerts.php
│ │ ├── GetAllMetrics.php
│ │ ├── GetAllDimensions.php
│ │ ├── GenerateGeoChart.php
│ │ ├── GeneratePieChart.php
│ │ ├── GetAllAccounts.php
│ │ ├── GenerateReport.php
│ │ ├── GetAllUrlChannels.php
│ │ ├── GetAllAdUnits.php
│ │ ├── GenerateTableChart.php
│ │ ├── GetAllSavedReports.php
│ │ ├── GetAllSavedAdStyles.php
│ │ ├── GetAllAdClients.php
│ │ ├── GenerateLineChart.php
│ │ ├── GenerateColumnChart.php
│ │ ├── GetAllAdClientsForAccount.php
│ │ ├── GetAccountTree.php
│ │ ├── GetAllAdUnitsForCustomChannel.php
│ │ └── HandleAccountErrors.php
│ ├── style.css
│ └── BaseExample.php
├── plus
│ ├── README
│ ├── style.css
│ └── simple.php
├── customSearch
│ └── index.php
├── pagespeed
│ ├── style.css
│ └── index.php
├── prediction
│ ├── README
│ ├── style.css
│ └── serviceAccount.php
├── analytics
│ ├── simple.php
│ └── demo
│ │ └── storage.php
├── urlshortener
│ └── style.css
├── batch.php
├── tasks
│ └── index.php
├── contacts
│ └── simple.php
├── affiliateNetwork
│ └── index.php
└── youtube
│ └── search.php
├── makeRelease.sh
├── src
├── service
│ └── Google_Service.php
├── auth
│ ├── Google_Signer.php
│ ├── Google_Verifier.php
│ ├── Google_Auth.php
│ ├── Google_AuthNone.php
│ ├── Google_LoginTicket.php
│ ├── Google_PemVerifier.php
│ └── Google_P12Signer.php
└── cache
│ └── Google_Cache.php
└── README
/static/Credentials.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mike42/google-api-php-client/master/static/Credentials.png
--------------------------------------------------------------------------------
/test/README:
--------------------------------------------------------------------------------
1 | These tests depend on PHPUnit, see
2 | http://www.phpunit.de/manual/current/en/installation.html for more instructions
3 |
--------------------------------------------------------------------------------
/NOTICE:
--------------------------------------------------------------------------------
1 | This product contains the following libraries:
2 |
3 | XRDS-Simple library from http://code.google.com/p/diso/
4 | Apache License 2.0
5 |
--------------------------------------------------------------------------------
/test/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ../src/contrib/
5 | ../src/external/
6 | ./
7 | ../src/cache/googleApcCache.php
8 | ../src/cache/googleMemcacheCache.php
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/examples/webfonts/simple.php:
--------------------------------------------------------------------------------
1 | setApplicationName("Google WebFonts PHP Starter Application");
7 |
8 | // Visit https://code.google.com/apis/console?api=webfonts
9 | // to generate your developer key.
10 | // $client->setDeveloperKey('insert_your_developer_key');
11 | $service = new Google_WebfontsService($client);
12 | $fonts = $service->webfonts->listWebfonts();
13 | print "
Fonts
" . print_r($fonts, true) . "
";
14 |
--------------------------------------------------------------------------------
/makeRelease.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | VERSION=0.6.7
4 | TMPDIR=/tmp/google-api-php-client
5 | RELFILE=/tmp/google-api-php-client-${VERSION}.tar.gz
6 |
7 | rm -f $RELFILE
8 | rm -rf $TMPDIR
9 | mkdir $TMPDIR
10 | cp -r * $TMPDIR
11 | cd $TMPDIR
12 | find . -name ".*" -exec rm -rf {} \; &>/dev/null
13 | find . -name "makeRelease.sh" -exec rm -rf {} \; &>/dev/null
14 | find . -name "local_*" -exec rm -rf {} \; &>/dev/null
15 | find . -name "static" -exec rm -rf {} \; &>/dev/null
16 | find . -name ".idea" -exec rm -rf {} \; &>/dev/null
17 | find . -name ".svn" -exec rm -rf {} \; &>/dev/null
18 | cd ..
19 | tar c google-api-php-client | gzip > $RELFILE
20 | rm -rf $TMPDIR
21 |
--------------------------------------------------------------------------------
/examples/adexchangebuyer/style.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | a {
18 | font-size: .9em;
19 | color: black;
20 | }
21 |
--------------------------------------------------------------------------------
/src/service/Google_Service.php:
--------------------------------------------------------------------------------
1 | setApplicationName('Google Translate PHP Starter Application');
7 |
8 | // Visit https://code.google.com/apis/console?api=translate to generate your
9 | // client id, client secret, and to register your redirect uri.
10 | // $client->setDeveloperKey('insert_your_developer_key');
11 | $service = new Google_TranslateService($client);
12 |
13 | $langs = $service->languages->listLanguages();
14 | print "Languages
" . print_r($langs, true) . "
";
15 |
16 | $translations = $service->translations->listTranslations('Hello', 'hi');
17 | print "Translations
" . print_r($translations, true) . "
";
18 |
--------------------------------------------------------------------------------
/src/auth/Google_Signer.php:
--------------------------------------------------------------------------------
1 |
24 | */
25 | abstract class Google_Signer {
26 | /**
27 | * Signs data, returns the signature as binary data.
28 | */
29 | abstract public function sign($data);
30 | }
31 |
--------------------------------------------------------------------------------
/src/auth/Google_Verifier.php:
--------------------------------------------------------------------------------
1 |
24 | */
25 | abstract class Google_Verifier {
26 | /**
27 | * Checks a signature, returns true if the signature is correct,
28 | * false otherwise.
29 | */
30 | abstract public function verify($data, $signature);
31 | }
32 |
--------------------------------------------------------------------------------
/test/general/ApiModelTest.php:
--------------------------------------------------------------------------------
1 | assertTrue(true);
25 | }
26 |
27 | }
--------------------------------------------------------------------------------
/examples/books/simple.php:
--------------------------------------------------------------------------------
1 | setApplicationName("My_Books_API_Example");
23 | $service = new Google_BooksService($client);
24 |
25 | $optParams = array('filter' => 'free-ebooks');
26 | $results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
27 |
28 | foreach ($results['items'] as $item) {
29 | print($item['volumeInfo']['title'] . '
');
30 | }
--------------------------------------------------------------------------------
/test/tasks/AllTasksTests.php:
--------------------------------------------------------------------------------
1 | setName('Google Tasks API tests');
27 | $suite->addTestSuite('TasksTest');
28 | return $suite;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/test/pagespeed/AllPageSpeedTests.php:
--------------------------------------------------------------------------------
1 | setName('Google PageSpeed API tests');
27 | $suite->addTestSuite('PageSpeedTest');
28 | return $suite;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/test/urlshortener/AllUrlShortenerTests.php:
--------------------------------------------------------------------------------
1 | setName('Google UrlShortener API tests');
27 | $suite->addTestSuite('UrlShortenerTests');
28 | return $suite;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/test/general/testdata/test_public_key.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDQjCCAiqgAwIBAgIJAMJ1Z12ZdGgLMA0GCSqGSIb3DQEBBQUAMB8xHTAbBgNV
3 | BAMTFHRlc3Qtc2VydmljZS1hY2NvdW50MB4XDTExMDgyMzIwNTczNFoXDTIxMDgy
4 | MDIwNTczNFowHzEdMBsGA1UEAxMUdGVzdC1zZXJ2aWNlLWFjY291bnQwggEiMA0G
5 | CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDpbFTjUXd02HFluI2G0kGKp1J5K2F8
6 | cYr7hKXHcsmKo6S/5g8AEYnnV1fEbiopoGt7UWV4T0LA99K0gqQ7QmvZKvFHXlgR
7 | XJH1aO+ZipVs3ycZOcjBMcw4hspFSi4IyQta64gASFUT5NaxRVGhzAuPlzH09dZQ
8 | RJ0NL54HccGNzEDaLx5usB8t2aRHbE4zRWJlNIsjgWnfVoiXwOv5oRhyfFMIaTu1
9 | eIp3XP1QAv5cuYS2U4ZJ+J7Gzg6E7t4PWqK7rGjnc5BJsVIoiL77K/xKUWABNgHz
10 | b6JuiEp3LX9f2H5+CKo/IJFWoyIYWdZiu69LZivife9sTXmDnOcZkisRAgMBAAGj
11 | gYAwfjAdBgNVHQ4EFgQU0RkXlevVO2zuTFP/ksFUbNkpm+kwTwYDVR0jBEgwRoAU
12 | 0RkXlevVO2zuTFP/ksFUbNkpm+mhI6QhMB8xHTAbBgNVBAMTFHRlc3Qtc2Vydmlj
13 | ZS1hY2NvdW50ggkAwnVnXZl0aAswDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUF
14 | AAOCAQEAT+3VKautn+uV7ZQWbfx6xrGaDZ5wVK9FWOTVKsjdXyp11jtoVkDONLz5
15 | 3J7wgppZWabPargIZUHe9/P6j7QTgNV2na2thGHtVRIRyDECnVrvhCn/IDpMeJjj
16 | IAuysmSITHGEwb4AvRC5HdqfWzBqAvRhjJ2crcHZpx5/KkYZgJz9ylGJCynxpbHU
17 | 1aRu4qpkQNB4t4z5EzNOSLkFw9vEtm0hNX76CsNJFd0XDEKDQI2Lsc0WfDzQ1ZQH
18 | UVzIoTmQDkYGylQOBVyxZoGI6fuSo8c2I1BKvsdBGhSPjePNvaKUbmLSwUsranhX
19 | 2Y1kn7xbDTUHymZ0+g5rDM9kWmhZfg==
20 | -----END CERTIFICATE-----
21 |
--------------------------------------------------------------------------------
/examples/shopping/simple.php:
--------------------------------------------------------------------------------
1 | setApplicationName("Google Shopping PHP Starter Application");
7 |
8 | // Visit https://code.google.com/apis/console?api=shopping to generate your
9 | // Simple API Key.
10 | //$client->setDeveloperKey('insert_your_api_key');
11 | $service = new Google_ShoppingService($client);
12 |
13 | // Valid source values are "public", "cx:cse", and "gan:pid"
14 | // See http://code.google.com/apis/shopping/search/v1/getting_started.html#products-feed
15 | $source = "public";
16 |
17 | // For more information about full text search with the shopping API, please
18 | // see http://code.google.com/apis/shopping/search/v1/getting_started.html#text-search
19 | $query = "\"mp3 player\" | ipod";
20 |
21 | //The order in which the API returns products is defined by a ranking criterion.
22 | // See http://code.google.com/apis/shopping/search/v1/getting_started.html#ranking
23 | $ranking = "relevancy";
24 |
25 | $results = $service->products->listProducts($source, array(
26 | "country" => "US",
27 | "q" => $query,
28 | "rankBy" => $ranking,
29 | ));
30 |
31 | print "Shopping Results
" . print_r($results, true) . "
";
32 |
--------------------------------------------------------------------------------
/src/auth/Google_Auth.php:
--------------------------------------------------------------------------------
1 |
24 | *
25 | */
26 | abstract class Google_Auth {
27 | abstract public function authenticate($service);
28 | abstract public function sign(Google_HttpRequest $request);
29 | abstract public function createAuthUrl($scope);
30 |
31 | abstract public function getAccessToken();
32 | abstract public function setAccessToken($accessToken);
33 | abstract public function setDeveloperKey($developerKey);
34 | abstract public function refreshToken($refreshToken);
35 | abstract public function revokeToken();
36 | }
37 |
--------------------------------------------------------------------------------
/examples/adsensehost/examples/StartAssociationSession.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class StartAssociationSession extends BaseExample {
29 | public function render() {
30 | // Retrieve report.
31 | $result = $this->adSenseHostService->associationsessions
32 | ->start('AFC', 'www.example.com/blog');
33 |
34 | $format = 'Association with ID "%s" and redirect URL "%s" was started.';
35 | $content = sprintf($format, $result['id'], $result['redirectUrl']);
36 |
37 | print $content;
38 | }
39 | }
40 |
41 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | Google APIs Client Library for PHP
2 | =====================================
3 |
4 | == Description
5 | The Google API Client Library enables you to work with Google APIs such as Google+, Drive, Tasks, or Latitude on your server.
6 |
7 | Requirements:
8 | PHP 5.2.x or higher [http://www.php.net/]
9 | PHP Curl extension [http://www.php.net/manual/en/intro.curl.php]
10 | PHP JSON extension [http://php.net/manual/en/book.json.php]
11 |
12 | Project page:
13 | http://code.google.com/p/google-api-php-client
14 |
15 | OAuth 2 instructions:
16 | http://code.google.com/p/google-api-php-client/wiki/OAuth2
17 |
18 | Report a defect or feature request here:
19 | http://code.google.com/p/google-api-php-client/issues/entry
20 |
21 | Subscribe to project updates in your feed reader:
22 | http://code.google.com/feeds/p/google-api-php-client/updates/basic
23 |
24 | Supported sample applications:
25 | http://code.google.com/p/google-api-php-client/wiki/Samples
26 |
27 | == Basic Example
28 | 'free-ebooks');
36 | $results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
37 |
38 | foreach ($results['items'] as $item) {
39 | print($item['volumeInfo']['title'] . '
');
40 | }
41 |
--------------------------------------------------------------------------------
/examples/calendar/simple.php:
--------------------------------------------------------------------------------
1 | setApplicationName("Google Calendar PHP Starter Application");
8 |
9 | // Visit https://code.google.com/apis/console?api=calendar to generate your
10 | // client id, client secret, and to register your redirect uri.
11 | // $client->setClientId('insert_your_oauth2_client_id');
12 | // $client->setClientSecret('insert_your_oauth2_client_secret');
13 | // $client->setRedirectUri('insert_your_oauth2_redirect_uri');
14 | // $client->setDeveloperKey('insert_your_developer_key');
15 | $cal = new Google_CalendarService($client);
16 | if (isset($_GET['logout'])) {
17 | unset($_SESSION['token']);
18 | }
19 |
20 | if (isset($_GET['code'])) {
21 | $client->authenticate($_GET['code']);
22 | $_SESSION['token'] = $client->getAccessToken();
23 | header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
24 | }
25 |
26 | if (isset($_SESSION['token'])) {
27 | $client->setAccessToken($_SESSION['token']);
28 | }
29 |
30 | if ($client->getAccessToken()) {
31 | $calList = $cal->calendarList->listCalendarList();
32 | print "Calendar List
" . print_r($calList, true) . "
";
33 |
34 |
35 | $_SESSION['token'] = $client->getAccessToken();
36 | } else {
37 | $authUrl = $client->createAuthUrl();
38 | print "Connect Me!";
39 | }
--------------------------------------------------------------------------------
/examples/adsensehost/examples/VerifyAssociationSession.php:
--------------------------------------------------------------------------------
1 |
30 | */
31 | class VerifyAssociationSession extends BaseExample {
32 | public function render() {
33 | // Retrieve report.
34 | $result = $this->adSenseHostService->associationsessions->verify(TOKEN);
35 |
36 | $format = 'Association for account "%s" has status "%s" and ID "%s".';
37 | $content = sprintf($format, $result['accountId'], $result['status'],
38 | $result['id']);
39 |
40 | print $content;
41 | }
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/test/pagespeed/PageSpeedTest.php:
--------------------------------------------------------------------------------
1 | service = new Google_PagespeedonlineService(BaseTest::$client);
25 | }
26 |
27 | public function testPageSpeed() {
28 | $psapi = $this->service->pagespeedapi;
29 | $result = $psapi->runpagespeed('http://code.google.com');
30 | $this->assertArrayHasKey('kind', $result);
31 | $this->assertArrayHasKey('id', $result);
32 | $this->assertArrayHasKey('responseCode', $result);
33 | $this->assertArrayHasKey('title', $result);
34 | $this->assertArrayHasKey('score', $result);
35 | $this->assertArrayHasKey('pageStats', $result);
36 | $this->assertArrayHasKey('version', $result);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/examples/siteVerification/simple.php:
--------------------------------------------------------------------------------
1 | setApplicationName("Google Site Verification PHP Sample");
8 |
9 | // Visit https://code.google.com/apis/console?api=siteVerification to generate
10 | // your client id, client secret, and to register your redirect uri.
11 | // $client->setClientId('insert_your_oauth2_client_id');
12 | // $client->setClientSecret('insert_your_oauth2_client_secret');
13 | // $client->setRedirectUri('insert_your_oauth2_redirect_uri');
14 | // $client->setDeveloperKey('insert_your_developer_key');
15 | $service = new Google_SiteVerificationService($client);
16 |
17 | if (isset($_GET['logout'])) {
18 | unset($_SESSION['token']);
19 | }
20 |
21 | if (isset($_GET['code'])) {
22 | $client->authenticate();
23 | $_SESSION['token'] = $client->getAccessToken();
24 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
25 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
26 | }
27 |
28 | if (isset($_SESSION['token'])) {
29 | $client->setAccessToken($_SESSION['token']);
30 | }
31 |
32 | if ($client->getAccessToken()) {
33 | $resources = $service->webResource->listWebResource();
34 | print '' . print_r($resources, true) . '
';
35 |
36 | $_SESSION['token'] = $client->getAccessToken();
37 | } else {
38 | $authUrl = $client->createAuthUrl();
39 | print "Connect Me!";
40 | }
--------------------------------------------------------------------------------
/examples/adexchangebuyer/examples/GetAllAccounts.php:
--------------------------------------------------------------------------------
1 | service->accounts->listAccounts();
35 |
36 | print 'Listing of user associated accounts
';
37 | foreach ($result['items'] as $account) {
38 | $this->printResult($account);
39 | }
40 | }
41 |
42 | /**
43 | * (non-PHPdoc)
44 | * @see BaseExample::getName()
45 | * @return string
46 | */
47 | public function getName() {
48 | return 'Get All Accounts';
49 | }
50 | }
51 |
52 |
--------------------------------------------------------------------------------
/examples/adexchangeseller/examples/GenerateSavedReport.php:
--------------------------------------------------------------------------------
1 |
29 | */
30 | class GenerateReport extends BaseExample {
31 | public function render() {
32 | $savedReportId = SAVED_REPORT_ID;
33 | // Retrieve report.
34 | $report = $this->adExchangeSellerService->reports_saved
35 | ->generate($savedReportId);
36 |
37 | if (isset($report['rows'])) {
38 | printReportTableHeader($report['headers']);
39 | printReportTableRows($report['rows']);
40 | printReportTableFooter();
41 | } else {
42 | printNoResultForTable(count($report['headers']));
43 | }
44 | }
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/test/urlshortener/UrlShortenerTests.php:
--------------------------------------------------------------------------------
1 | service = new Google_UrlshortenerService(BaseTest::$client);
28 | }
29 |
30 | public function testUrlShort() {
31 | $url = new Google_Url();
32 | $url->longUrl = "http://google.com";
33 |
34 | $shortUrl = $this->service->url->insert($url);
35 | $this->assertEquals('urlshortener#url', $shortUrl['kind']);
36 | $this->assertEquals('http://google.com/', $shortUrl['longUrl']);
37 | }
38 |
39 | public function testEmptyJsonResponse() {
40 | $optParams = array('fields' => '');
41 | $resp = $this->service->url->get('http://goo.gl/KkHq8', $optParams);
42 |
43 | $this->assertEquals(array(), $resp);
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/examples/adsense/examples/GenerateSavedReport.php:
--------------------------------------------------------------------------------
1 |
29 | */
30 | class GenerateReport extends BaseExample {
31 | public function render() {
32 | $accountId = ACCOUNT_ID;
33 | $savedReportId = SAVED_REPORT_ID;
34 | // Retrieve report.
35 | $report = $this->adSenseService->account_reports_saved
36 | ->generate($accountId, $savedReportId);
37 |
38 | if (isset($report['rows'])) {
39 | printReportTableHeader($report['headers']);
40 | printReportTableRows($report['rows']);
41 | printReportTableFooter();
42 | } else {
43 | printNoResultForTable(count($report['headers']));
44 | }
45 | }
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/examples/adsensehost/examples/AddUrlChannelToHost.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class AddUrlChannelToHost extends BaseExample {
30 | public function render() {
31 | $adClientId = HOST_AD_CLIENT_ID;
32 |
33 | $urlChannel = new Google_UrlChannel();
34 | $urlChannel->setUrlPattern(sprintf('www.example.com/%s',
35 | $this->getUniqueName()));
36 |
37 | // Retrieve URL channels list, and display it.
38 | $result = $this->adSenseHostService->urlchannels
39 | ->insert($adClientId, $urlChannel);
40 | $mainFormat = 'URL channel with id "%s" and URL pattern "%s" was created.';
41 | $content = sprintf($mainFormat, $result['id'], $result['urlPattern']);
42 | print $content;
43 | }
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/src/cache/Google_Cache.php:
--------------------------------------------------------------------------------
1 |
25 | */
26 | abstract class Google_Cache {
27 |
28 | /**
29 | * Retrieves the data for the given key, or false if they
30 | * key is unknown or expired
31 | *
32 | * @param String $key The key who's data to retrieve
33 | * @param boolean|int $expiration Expiration time in seconds
34 | *
35 | */
36 | abstract function get($key, $expiration = false);
37 |
38 | /**
39 | * Store the key => $value set. The $value is serialized
40 | * by this function so can be of any type
41 | *
42 | * @param string $key Key of the data
43 | * @param string $value data
44 | */
45 | abstract function set($key, $value);
46 |
47 | /**
48 | * Removes the key/data pair for the given $key
49 | *
50 | * @param String $key
51 | */
52 | abstract function delete($key);
53 | }
54 |
55 |
56 |
--------------------------------------------------------------------------------
/test/BaseTest.php:
--------------------------------------------------------------------------------
1 | getAccessToken()) {
36 | if (isset($apiConfig['oauth_test_token'])) {
37 | BaseTest::$client->setAccessToken($apiConfig['oauth_test_token']);
38 | }
39 | }
40 | }
41 | }
42 |
43 | public function __destruct() {
44 | global $apiConfig;
45 | $apiConfig['oauth_test_token'] = self::$client->getAccessToken();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/examples/adsense/examples/GetAllAlerts.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class GetAllAlerts extends BaseExample {
29 | public function render() {
30 | $listClass = 'list';
31 | printListHeader($listClass);
32 | // Retrieve alert list, and display it.
33 | $result = $this->adSenseService->alerts->listAlerts();
34 | if (isset($result['items'])) {
35 | $alerts = $result['items'];
36 | foreach ($alerts as $alert) {
37 | $format = 'Alert id "%s" with severity "%s" and type "%s" was found.';
38 | $content = sprintf(
39 | $format, $alert['id'], $alert['severity'], $alert['type']);
40 | printListElement($content);
41 | }
42 | } else {
43 | printNoResultForList();
44 | }
45 | printListFooter();
46 | }
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/examples/adexchangeseller/examples/GetAllAlerts.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class GetAllAlerts extends BaseExample {
29 | public function render() {
30 | $listClass = 'list';
31 | printListHeader($listClass);
32 | // Retrieve alert list, and display it.
33 | $result = $this->adExchangeSellerService->alerts->listAlerts();
34 | if (isset($result['items'])) {
35 | $alerts = $result['items'];
36 | foreach ($alerts as $alert) {
37 | $format = 'Alert id "%s" with severity "%s" and type "%s" was found.';
38 | $content = sprintf(
39 | $format, $alert['id'], $alert['severity'], $alert['type']);
40 | printListElement($content);
41 | }
42 | } else {
43 | printNoResultForList();
44 | }
45 | printListFooter();
46 | }
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/examples/adexchangebuyer/examples/GetDirectDeals.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class GetDirectDeals extends BaseExample {
30 | public function run() {
31 | $result = $this->service->directDeals->listDirectDeals();
32 |
33 | printf('Listing of user associated direct deals
');
34 |
35 | if (!isset($result['direct_deals']) || !count($result['direct_deals'])) {
36 | print 'No direct deals found
';
37 | return;
38 | }
39 | foreach ($result['direct_deals'] as $directDeal) {
40 | $this->printResult($directDeal);
41 | }
42 | }
43 |
44 | /**
45 | * (non-PHPdoc)
46 | * @see BaseExample::getName()
47 | * @return string
48 | */
49 | public function getName() {
50 | return "Get Direct Deals";
51 | }
52 | }
53 |
54 |
--------------------------------------------------------------------------------
/examples/adsensehost/examples/DeleteUrlChannelOnHost.php:
--------------------------------------------------------------------------------
1 |
32 | */
33 | class DeleteUrlChannelOnHost extends BaseExample {
34 | public function render() {
35 | $adClientId = HOST_AD_CLIENT_ID;
36 | $urlChannelId = URL_CHANNEL_ID;
37 |
38 | // Retrieve URL channels list, and display it.
39 | $result = $this->adSenseHostService->urlchannels
40 | ->delete($adClientId, $urlChannelId);
41 | $mainFormat = 'URL channel with ID "%s" was deleted.';
42 | $content = sprintf($mainFormat, $result['id']);
43 | print $content;
44 | }
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/examples/adsensehost/examples/AddCustomChannelToHost.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class AddCustomChannelToHost extends BaseExample {
30 | public function render() {
31 | $adClientId = HOST_AD_CLIENT_ID;
32 |
33 | $customChannel = new Google_CustomChannel();
34 | $customChannel->setName(sprintf('Sample Channel #%s',
35 | $this->getUniqueName()));
36 |
37 | // Retrieve custom channels list, and display it.
38 | $result = $this->adSenseHostService->customchannels
39 | ->insert($adClientId, $customChannel);
40 | $mainFormat =
41 | 'Custom channel with ID "%s", code "%s" and name "%s" was created.';
42 | $content = sprintf($mainFormat, $result['id'], $result['code'],
43 | $result['name']);
44 | print $content;
45 | }
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/examples/adsensehost/examples/DeleteCustomChannelOnHost.php:
--------------------------------------------------------------------------------
1 |
32 | */
33 | class DeleteCustomChannelOnHost extends BaseExample {
34 | public function render() {
35 | $adClientId = HOST_AD_CLIENT_ID;
36 | $customChannelId = CUSTOM_CHANNEL_ID;
37 |
38 | // Retrieve custom channels list, and display it.
39 | $result = $this->adSenseHostService->customchannels
40 | ->delete($adClientId, $customChannelId);
41 | $mainFormat = 'Custom channel with ID "%s" was deleted.';
42 | $content = sprintf($mainFormat, $result['id']);
43 | print $content;
44 | }
45 | }
46 |
47 |
--------------------------------------------------------------------------------
/examples/adsense/examples/GetAllMetrics.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class GetAllMetrics extends BaseExample {
29 | public function render() {
30 | $listClass = 'list';
31 | printListHeader($listClass);
32 | // Retrieve metric list, and display it.
33 | $result = $this->adSenseService->metadata_metrics->listMetadataMetrics();
34 | if (isset($result['items'])) {
35 | $metrics = $result['items'];
36 | foreach ($metrics as $metric) {
37 | $format = 'Metric id "%s" for product(s): [%s] was found.';
38 | $content = sprintf(
39 | $format,
40 | $metric['id'],
41 | implode(', ', $metric['supportedProducts']));
42 | printListElement($content);
43 | }
44 | } else {
45 | printNoResultForList();
46 | }
47 | printListFooter();
48 | }
49 | }
50 |
51 |
--------------------------------------------------------------------------------
/examples/plus/README:
--------------------------------------------------------------------------------
1 | Google+ PHP Starter Application
2 | =====================================
3 |
4 | == Description
5 | This application helps you get started writing a Google+ PHP application.
6 |
7 | Requirements:
8 | PHP 5.2.x or higher [http://www.php.net/]
9 | PHP Curl extension [http://www.php.net/manual/en/intro.curl.php]
10 | PHP JSON extension [http://php.net/manual/en/book.json.php]
11 |
12 | Getting Started:
13 | 1) Visit https://code.google.com/apis/console/?api=plus to register your application.
14 | - From the "Project Home" screen, activate access to "Google+ API".
15 | - Click on "API Access" in the left column
16 | - Click the button labeled "Create an OAuth2 client ID"
17 | - Give your application a name and click "Next"
18 | - Select "Web Application" as the "Application type"
19 | - click "Create client ID"
20 | - click "Edit..." for your new client ID
21 | - Under the callback URL, enter the location of your PHP application.
22 |
23 | 2) Update index.php with the redirect uri, consumer key, secret, and developer key you obtained in step 1.
24 | - Update 'insert_your_oauth2_client_id' with your oauth2 client id.
25 | - Update 'insert_your_oauth2_client_secret' with your oauth2 client secret.
26 | - Update 'insert_your_oauth2_redirect_uri' with the fully qualified redirect URI.
27 | - Update 'insert_your_developer_key' with your developer key.
28 | This is listed under "Simple API Access" at the very bottom in the Google API Console.
29 |
30 | 3) You are now ready to load index.php on your web server.
31 |
32 | OAuth 2 instructions:
33 | http://code.google.com/p/google-api-php-client/wiki/OAuth2
34 |
35 | Supported sample applications:
36 | http://code.google.com/p/google-api-php-client/wiki/Samples
--------------------------------------------------------------------------------
/examples/adexchangeseller/examples/GetAllMetrics.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class GetAllMetrics extends BaseExample {
29 | public function render() {
30 | $listClass = 'list';
31 | printListHeader($listClass);
32 | // Retrieve metric list, and display it.
33 | $result = $this->adExchangeSellerService->metadata_metrics
34 | ->listMetadataMetrics();
35 | if (isset($result['items'])) {
36 | $metrics = $result['items'];
37 | foreach ($metrics as $metric) {
38 | $format = 'Metric id "%s" for product(s): [%s] was found.';
39 | $content = sprintf(
40 | $format,
41 | $metric['id'],
42 | implode(', ', $metric['supportedProducts']));
43 | printListElement($content);
44 | }
45 | } else {
46 | printNoResultForList();
47 | }
48 | printListFooter();
49 | }
50 | }
51 |
52 |
--------------------------------------------------------------------------------
/examples/adsensehost/examples/DeleteAdUnitOnPublisher.php:
--------------------------------------------------------------------------------
1 |
33 | */
34 | class DeleteAdUnitOnPublisher extends BaseExample {
35 | public function render() {
36 | $accountId = PUBLISHER_ACCOUNT_ID;
37 | $adClientId = PUBLISHER_AD_CLIENT_ID;
38 | $adUnitId = PUBLISHER_AD_UNIT_ID;
39 |
40 | // Retrieve custom channels list, and display it.
41 | $result = $this->adSenseHostService->accounts_adunits
42 | ->delete($accountId, $adClientId, $adUnitId);
43 | $mainFormat = 'Ad unit with ID "%s" was deleted.';
44 | $content = sprintf($mainFormat, $result['id']);
45 | print $content;
46 | }
47 | }
48 |
49 |
--------------------------------------------------------------------------------
/examples/customSearch/index.php:
--------------------------------------------------------------------------------
1 | setApplicationName('Google CustomSearch PHP Starter Application');
23 | // Docs: http://code.google.com/apis/customsearch/v1/using_rest.html
24 | // Visit https://code.google.com/apis/console?api=customsearch to generate
25 | // your developer key (simple api key).
26 | // $client->setDeveloperKey('INSERT_your_developer_key');
27 | $search = new Google_CustomsearchService($client);
28 |
29 |
30 | // Example executing a search with your custom search id.
31 | $result = $search->cse->listCse('burrito', array(
32 | 'cx' => 'INSERT_SEARCH_ENGINE_ID', // The custom search engine ID to scope this search query.
33 | ));
34 | print "" . print_r($result, true) . "
";
35 |
36 | // Example executing a search with the URL of a linked custom search engine.
37 | $result = $search->cse->listCse('burrito', array(
38 | 'cref' => 'http://www.google.com/cse/samples/vegetarian.xml',
39 | ));
40 | print "" . print_r($result, true) . "
";
--------------------------------------------------------------------------------
/examples/adsense/examples/GetAllDimensions.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class GetAllDimensions extends BaseExample {
29 | public function render() {
30 | $listClass = 'list';
31 | printListHeader($listClass);
32 | // Retrieve dimension list, and display it.
33 | $result = $this->adSenseService->metadata_dimensions
34 | ->listMetadataDimensions();
35 | if (isset($result['items'])) {
36 | $dimensions = $result['items'];
37 | foreach ($dimensions as $dimension) {
38 | $format = 'Dimension id "%s" for product(s): [%s] was found.';
39 | $content = sprintf(
40 | $format,
41 | $dimension['id'],
42 | implode(', ', $dimension['supportedProducts']));
43 | printListElement($content);
44 | }
45 | } else {
46 | printNoResultForList();
47 | }
48 | printListFooter();
49 | }
50 | }
51 |
52 |
--------------------------------------------------------------------------------
/examples/pagespeed/style.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Google Inc.
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 |
16 | body {
17 | font-family: Arial,sans-serif;
18 | margin: auto;
19 | white-space: nowrap;
20 | }
21 |
22 | .box {
23 | border: .5em solid #E3E9FF;
24 | -webkit-box-orient: vertical;
25 | -webkit-box-align: center;
26 | -moz-box-orient: vertical;
27 | -moz-box-align: center;
28 |
29 | display: block;
30 | box-orient: vertical;
31 | box-align: center;
32 |
33 | width: 500px;
34 | height: auto;
35 |
36 | margin: auto;
37 | padding: 10px;
38 | }
39 |
40 | .search {
41 | -webkit-box-flex: 1;
42 | -moz-box-flex: 1;
43 | box-flex: 1;
44 | width: 100px;
45 | }
46 |
47 | .result {
48 | -webkit-box-flex: 2;
49 | -moz-box-flex: 2;
50 | box-flex: 2;
51 | width:100%;
52 | }
53 | .url {
54 | color: #019;
55 | width: 22em;
56 | font-size: 100%;
57 | vertical-align: middle;
58 | padding: 1px;
59 | background-color: white;
60 | border: 1px inset;
61 | cursor: auto;
62 | margin: 0em;
63 | text-indent: 0px;
64 | display: inline-block;
65 | }
66 |
67 | header {
68 | color:#000;
69 | padding:2px 5px;
70 | font-size:100%;
71 | width: 400px;
72 | margin: auto;
73 | text-align: center
74 | }
--------------------------------------------------------------------------------
/examples/adexchangeseller/examples/GetAllDimensions.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class GetAllDimensions extends BaseExample {
29 | public function render() {
30 | $listClass = 'list';
31 | printListHeader($listClass);
32 | // Retrieve dimension list, and display it.
33 | $result = $this->adExchangeSellerService->metadata_dimensions
34 | ->listMetadataDimensions();
35 | if (isset($result['items'])) {
36 | $dimensions = $result['items'];
37 | foreach ($dimensions as $dimension) {
38 | $format = 'Dimension id "%s" for product(s): [%s] was found.';
39 | $content = sprintf(
40 | $format,
41 | $dimension['id'],
42 | implode(', ', $dimension['supportedProducts']));
43 | printListElement($content);
44 | }
45 | } else {
46 | printNoResultForList();
47 | }
48 | printListFooter();
49 | }
50 | }
51 |
52 |
--------------------------------------------------------------------------------
/examples/prediction/README:
--------------------------------------------------------------------------------
1 | Google Prediction API PHP Starter Application
2 | =====================================
3 |
4 | == Description
5 | This application helps you get started writing a Google Prediction API
6 | PHP application. It's based on a similar app written for the Google+ API.
7 |
8 | Requirements:
9 | PHP 5.2.x or higher [http://www.php.net/]
10 |
11 | Getting Started:
12 | 1) Visit https://code.google.com/apis/console/?api=prediction to
13 | register your application.
14 |
15 | - From the "Services" tab, activate access to "Prediction API".
16 | - Click on "API Access" in the left column
17 | - Click the button labeled "Create an OAuth2 client ID"
18 | - Give your application a name and click "Next"
19 | - Select "Web Application" as the "Application type"
20 | - click "Create client ID"
21 | - click "Edit..." for your new client ID
22 | - Under the callback URL, enter the location of your PHP application.
23 |
24 | 2) Update index.php with the redirect uri, client ID, client secret, and
25 | API key you obtained in step 1.
26 |
27 | - Update 'insert_your_oauth2_client_id' with your oauth2 client id.
28 | - Update 'insert_your_oauth2_client_secret' with your oauth2 client secret.
29 | - Update 'insert_your_oauth2_redirect_uri' with the fully qualified
30 | redirect URI.
31 | - Update 'insert_your_developer_key' with your developer key.
32 |
33 | The API key is listed under "Simple API Access" section at the bottom
34 | of the Google API Console site under the API Access tab.
35 |
36 | 3) You are now ready to load index.php on your web server.
37 |
38 | OAuth 2.0 instructions:
39 | http://code.google.com/p/google-api-php-client/wiki/OAuth2
40 |
41 | Supported sample applications:
42 | http://code.google.com/p/google-api-php-client/wiki/Samples
43 |
--------------------------------------------------------------------------------
/test/general/ApiBatchRequestTest.php:
--------------------------------------------------------------------------------
1 | plus = new Google_PlusService(BaseTest::$client);
30 | }
31 |
32 | public function testBatchRequest() {
33 | $batch = new Google_BatchRequest();
34 |
35 | BaseTest::$client->setUseBatch(true);
36 | $batch->add($this->plus->people->get('me'), 'key1');
37 | $batch->add($this->plus->people->get('me'), 'key2');
38 | $batch->add($this->plus->people->get('me'), 'key3');
39 |
40 | $result = $batch->execute();
41 | $this->assertTrue(isset($result['response-key1']));
42 | $this->assertTrue(isset($result['response-key2']));
43 | $this->assertTrue(isset($result['response-key3']));
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/examples/adsense/style.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /* Table */
18 | table {
19 | border-collapse: collapse; /* Equivalent for cellspacing=0 */
20 | }
21 |
22 | thead tr {
23 | background: #eee;
24 | border: 1px solid #bbb;
25 | border-bottom: 1px solid #ccc;
26 | }
27 |
28 | tbody tr {
29 | background: #f9f9f9;
30 | border-bottom: 1px solid #ccc;
31 | }
32 |
33 | th,
34 | td {
35 | padding: 5px 25px 5px 5px;
36 | border-left: 1px solid #ccc;
37 | border-right: 1px solid #ccc;
38 | }
39 |
40 | /* Lists */
41 | .clients,
42 | .list {
43 | border: 1px solid #e9e9e9;
44 | margin: 0 0 2em 0;
45 | }
46 |
47 | .clients li,
48 | .list li {
49 | border-bottom: 1px solid #e9e9e9;
50 | font-size: .9em;
51 | background: #EEE;
52 | padding: 3px;
53 | margin: 0;
54 | }
55 |
56 | .clients ul,
57 | ul.nav {
58 | padding: 0;
59 | margin: 0;
60 | list-style: none;
61 | }
62 |
63 | .clients ul li,
64 | .nav li {
65 | padding: 3px;
66 | margin: 0 0 0 .5em;
67 | background: #f9f9f9;
68 | }
69 |
70 | a {
71 | font-size: .9em;
72 | color: black;
73 | }
74 |
75 | a:link,
76 | a:active,
77 | a:visited {
78 | text-decoration: none;
79 | }
80 |
81 | .highlight:hover {
82 | background: orange;
83 | }
84 |
--------------------------------------------------------------------------------
/examples/adsensehost/style.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2012 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /* Table */
18 | table {
19 | border-collapse: collapse; /* Equivalent for cellspacing=0 */
20 | }
21 |
22 | thead tr {
23 | background: #eee;
24 | border: 1px solid #bbb;
25 | border-bottom: 1px solid #ccc;
26 | }
27 |
28 | tbody tr {
29 | background: #f9f9f9;
30 | border-bottom: 1px solid #ccc;
31 | }
32 |
33 | th,
34 | td {
35 | padding: 5px 25px 5px 5px;
36 | border-left: 1px solid #ccc;
37 | border-right: 1px solid #ccc;
38 | }
39 |
40 | /* Lists */
41 | .clients,
42 | .list {
43 | border: 1px solid #e9e9e9;
44 | margin: 0 0 2em 0;
45 | }
46 |
47 | .clients li,
48 | .list li {
49 | border-bottom: 1px solid #e9e9e9;
50 | font-size: .9em;
51 | background: #EEE;
52 | padding: 3px;
53 | margin: 0;
54 | }
55 |
56 | .clients ul,
57 | ul.nav {
58 | padding: 0;
59 | margin: 0;
60 | list-style: none;
61 | }
62 |
63 | .clients ul li,
64 | .nav li {
65 | padding: 3px;
66 | margin: 0 0 0 .5em;
67 | background: #f9f9f9;
68 | }
69 |
70 | a {
71 | font-size: .9em;
72 | color: black;
73 | }
74 |
75 | a:link,
76 | a:active,
77 | a:visited {
78 | text-decoration: none;
79 | }
80 |
81 | .highlight:hover {
82 | background: orange;
83 | }
84 |
--------------------------------------------------------------------------------
/test/general/OAuthHelper.php:
--------------------------------------------------------------------------------
1 | setClientId('INSERT_CLIENT_ID');
26 | //$client->setClientSecret('INSERT_CLIENT_SECRET');
27 | $client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
28 | $client->setScopes(array(
29 | 'https://www.googleapis.com/auth/plus.me',
30 | 'https://www.googleapis.com/auth/latitude',
31 | 'https://www.googleapis.com/auth/moderator',
32 | 'https://www.googleapis.com/auth/tasks',
33 | 'https://www.googleapis.com/auth/siteverification',
34 | 'https://www.googleapis.com/auth/urlshortener',
35 | 'https://www.googleapis.com/auth/adsense.readonly',
36 | ));
37 |
38 | $authUrl = $client->createAuthUrl();
39 |
40 | print "Please visit:\n$authUrl\n\n";
41 | print "Please enter the auth code:\n";
42 | $authCode = trim(fgets(STDIN));
43 |
44 | $_GET['code'] = $authCode;
45 | $accessToken = $client->authenticate();
46 |
47 | var_dump($accessToken);
48 |
--------------------------------------------------------------------------------
/examples/adexchangeseller/style.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Google Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /* Table */
18 | table {
19 | border-collapse: collapse; /* Equivalent for cellspacing=0 */
20 | }
21 |
22 | thead tr {
23 | background: #eee;
24 | border: 1px solid #bbb;
25 | border-bottom: 1px solid #ccc;
26 | }
27 |
28 | tbody tr {
29 | background: #f9f9f9;
30 | border-bottom: 1px solid #ccc;
31 | }
32 |
33 | th,
34 | td {
35 | padding: 5px 25px 5px 5px;
36 | border-left: 1px solid #ccc;
37 | border-right: 1px solid #ccc;
38 | }
39 |
40 | /* Lists */
41 | .clients,
42 | .list {
43 | border: 1px solid #e9e9e9;
44 | margin: 0 0 2em 0;
45 | }
46 |
47 | .clients li,
48 | .list li {
49 | border-bottom: 1px solid #e9e9e9;
50 | font-size: .9em;
51 | background: #EEE;
52 | padding: 3px;
53 | margin: 0;
54 | }
55 |
56 | .clients ul,
57 | ul.nav {
58 | padding: 0;
59 | margin: 0;
60 | list-style: none;
61 | }
62 |
63 | .clients ul li,
64 | .nav li {
65 | padding: 3px;
66 | margin: 0 0 0 .5em;
67 | background: #f9f9f9;
68 | }
69 |
70 | a {
71 | font-size: .9em;
72 | color: black;
73 | }
74 |
75 | a:link,
76 | a:active,
77 | a:visited {
78 | text-decoration: none;
79 | }
80 |
81 | .highlight:hover {
82 | background: orange;
83 | }
84 |
--------------------------------------------------------------------------------
/src/auth/Google_AuthNone.php:
--------------------------------------------------------------------------------
1 |
21 | * @author Chirag Shah
22 | */
23 | class Google_AuthNone extends Google_Auth {
24 | public $key = null;
25 |
26 | public function __construct() {
27 | global $apiConfig;
28 | if (!empty($apiConfig['developer_key'])) {
29 | $this->setDeveloperKey($apiConfig['developer_key']);
30 | }
31 | }
32 |
33 | public function setDeveloperKey($key) {$this->key = $key;}
34 | public function authenticate($service) {/*noop*/}
35 | public function setAccessToken($accessToken) {/* noop*/}
36 | public function getAccessToken() {return null;}
37 | public function createAuthUrl($scope) {return null;}
38 | public function refreshToken($refreshToken) {/* noop*/}
39 | public function revokeToken() {/* noop*/}
40 |
41 | public function sign(Google_HttpRequest $request) {
42 | if ($this->key) {
43 | $request->setUrl($request->getUrl() . ((strpos($request->getUrl(), '?') === false) ? '?' : '&')
44 | . 'key='.urlencode($this->key));
45 | }
46 | return $request;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/test/general/GeneralTests.php:
--------------------------------------------------------------------------------
1 | addTestSuite('AuthTest');
37 | $suite->addTestSuite('CacheTest');
38 | $suite->addTestSuite('IoTest');
39 | $suite->addTestSuite('ServiceTest');
40 | $suite->addTestSuite('ApiBatchRequestTest');
41 | $suite->addTestSuite('ApiClientTest');
42 | $suite->addTestSuite('ApiOAuth2Test');
43 | $suite->addTestSuite('ApiCacheParserTest');
44 | $suite->addTestSuite('ApiMediaFileUploadTest');
45 | $suite->addTestSuite('RestTest');
46 | return $suite;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/examples/adsense/examples/GenerateGeoChart.php:
--------------------------------------------------------------------------------
1 |
25 | */
26 | class GenerateGeoChart extends BaseExample {
27 | public function render() {
28 | $startDate = $this->getSixMonthsBeforeNow();
29 | $endDate = $this->getNow();
30 | $optParams = array(
31 | 'metric' => array('PAGE_VIEWS'),
32 | 'dimension' => array('COUNTRY_NAME'),
33 | 'sort' => 'COUNTRY_NAME'
34 | );
35 | // Retrieve report.
36 | $report = $this->adSenseService->reports
37 | ->generate($startDate, $endDate, $optParams);
38 | $data = $report['rows'];
39 | // We need to convert the metrics to numeric values for the chart.
40 | foreach ($data as &$row) {
41 | $row[1] = (int)$row[1];
42 | }
43 | $data = json_encode($data);
44 | $columns = array(
45 | array('string', 'Country name'),
46 | array('number', 'Page views'),
47 | );
48 | $type = 'GeoChart';
49 | $options = json_encode(array());
50 | print generateChartHtml($data, $columns, $type, $options);
51 | }
52 | }
53 |
54 |
--------------------------------------------------------------------------------
/examples/adsense/examples/GeneratePieChart.php:
--------------------------------------------------------------------------------
1 |
25 | */
26 | class GeneratePieChart extends BaseExample {
27 | public function render() {
28 | $startDate = $this->getSixMonthsBeforeNow();
29 | $endDate = $this->getNow();
30 | $optParams = array(
31 | 'metric' => array('AD_REQUESTS'),
32 | 'dimension' => array('AD_CLIENT_ID'),
33 | 'sort' => 'AD_CLIENT_ID'
34 | );
35 | // Retrieve report.
36 | $report = $this->adSenseService->reports
37 | ->generate($startDate, $endDate, $optParams);
38 | $data = $report['rows'];
39 | // We need to convert the metrics to numeric values for the chart.
40 | foreach ($data as &$row) {
41 | $row[1] = (int)$row[1];
42 | }
43 | $data = json_encode($data);
44 | $columns = array(
45 | array('string', 'Ad client id'),
46 | array('number', 'Ad requests')
47 | );
48 | $type = 'PieChart';
49 | $options = json_encode(
50 | array('title' => 'Ads requests per ad client id')
51 | );
52 | print generateChartHtml($data, $columns, $type, $options);
53 | }
54 | }
55 |
56 |
--------------------------------------------------------------------------------
/examples/adexchangeseller/examples/GetAllPreferredDeals.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class GetAllPreferredDeals extends BaseExample {
29 | public function render() {
30 | $listClass = 'list';
31 | printListHeader($listClass);
32 | // Retrieve preferred deal list, and display it.
33 | $result = $this->adExchangeSellerService->preferreddeals
34 | ->listPreferreddeals();
35 | if (isset($result['items'])) {
36 | $deals = $result['items'];
37 | foreach ($deals as $deal) {
38 | $content = sprintf('Deal id "%s" ', $deal['id']);
39 | if (isset($deal['advertiserName'])) {
40 | $content .= sprintf('for advertiser "%s" ', $deal['advertiserName']);
41 | }
42 | if (isset($deal['buyerNetworkName'])) {
43 | $content .= sprintf('on network "%s" ', $deal['buyerNetworkName']);
44 | }
45 | $content .= 'was found.';
46 | printListElement($content);
47 | }
48 | } else {
49 | printNoResultForList();
50 | }
51 | printListFooter();
52 | }
53 | }
54 |
55 |
--------------------------------------------------------------------------------
/test/AllTests.php:
--------------------------------------------------------------------------------
1 | setName('All Google API PHP Client tests');
37 | // TODO(slangley): Enable all of these tests - They do not work as part of
38 | // the download and we need them before we can ship this in the SDK.
39 | //$suite->addTestSuite(AllTasksTests::suite());
40 | //$suite->addTestSuite(AllPageSpeedTests::suite());
41 | //$suite->addTestSuite(AllUrlShortenerTests::suite());
42 | //$suite->addTestSuite(AllPlusTests::suite());
43 | //$suite->addTestSuite(AdsenseTests::suite());
44 |
45 | $suite->addTestSuite(GeneralTests::suite());
46 | return $suite;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/examples/adsense/examples/GetAllAccounts.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class GetAllAccounts extends BaseExample {
29 | public function render() {
30 | $optParams['maxResults'] = AD_MAX_PAGE_SIZE;
31 | $listClass = 'list';
32 | printListHeader($listClass);
33 | $pageToken = null;
34 | do {
35 | $optParams['pageToken'] = $pageToken;
36 | // Retrieve account list, and display it.
37 | $result = $this->adSenseService->accounts->listAccounts($optParams);
38 | $accounts = $result['items'];
39 | if (isset($accounts)) {
40 | foreach ($accounts as $account) {
41 | $format = 'Account with ID "%s" and name "%s" was found.';
42 | $content = sprintf(
43 | $format, $account['id'], $account['name']);
44 | printListElement($content);
45 | }
46 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
47 | : null;
48 | } else {
49 | printNoResultForList();
50 | }
51 | } while ($pageToken);
52 | printListFooter();
53 | }
54 | }
55 |
56 |
--------------------------------------------------------------------------------
/examples/adsensehost/examples/UpdateCustomChannelOnHost.php:
--------------------------------------------------------------------------------
1 |
33 | */
34 | class UpdateCustomChannelOnHost extends BaseExample {
35 | public function render() {
36 | $adClientId = HOST_AD_CLIENT_ID;
37 | $customChannelId = CUSTOM_CHANNEL_ID;
38 |
39 | $customChannel = new Google_CustomChannel();
40 | $customChannel->setName(sprintf('Updated Sample Channel #%s',
41 | $this->getUniqueName()));
42 |
43 | // Retrieve custom channels list, and display it.
44 | $result = $this->adSenseHostService->customchannels
45 | ->patch($adClientId, $customChannelId, $customChannel);
46 | $mainFormat =
47 | 'Custom channel with ID "%s" was updated with name "%s".';
48 | $content = sprintf($mainFormat, $result['id'], $result['name']);
49 | print $content;
50 | }
51 | }
52 |
53 |
--------------------------------------------------------------------------------
/examples/adsense/examples/GenerateReport.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class GenerateReport extends BaseExample {
30 | public function render() {
31 | $startDate = $this->getSixMonthsBeforeNow();
32 | $endDate = $this->getNow();
33 | $optParams = array(
34 | 'metric' => array(
35 | 'PAGE_VIEWS', 'AD_REQUESTS', 'AD_REQUESTS_COVERAGE',
36 | 'CLICKS', 'AD_REQUESTS_CTR', 'COST_PER_CLICK', 'AD_REQUESTS_RPM',
37 | 'EARNINGS'),
38 | 'dimension' => 'DATE',
39 | 'sort' => 'DATE',
40 | 'filter' => array(
41 | 'AD_CLIENT_ID==' . AD_CLIENT_ID
42 | )
43 | );
44 | // Retrieve report.
45 | $report = $this->adSenseService->reports
46 | ->generate($startDate, $endDate, $optParams);
47 |
48 | if (isset($report['rows'])) {
49 | printReportTableHeader($report['headers']);
50 | printReportTableRows($report['rows']);
51 | printReportTableFooter();
52 | } else {
53 | printNoResultForTable(count($report['headers']));
54 | }
55 | }
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/examples/adexchangeseller/examples/GenerateReport.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class GenerateReport extends BaseExample {
30 | public function render() {
31 | $startDate = $this->getSixMonthsBeforeNow();
32 | $endDate = $this->getNow();
33 | $optParams = array(
34 | 'metric' => array(
35 | 'PAGE_VIEWS', 'AD_REQUESTS', 'AD_REQUESTS_COVERAGE',
36 | 'CLICKS', 'AD_REQUESTS_CTR', 'COST_PER_CLICK', 'AD_REQUESTS_RPM',
37 | 'EARNINGS'),
38 | 'dimension' => 'DATE',
39 | 'sort' => 'DATE',
40 | 'filter' => array(
41 | 'AD_CLIENT_ID==' . AD_CLIENT_ID
42 | )
43 | );
44 | // Retrieve report.
45 | $report = $this->adExchangeSellerService->reports
46 | ->generate($startDate, $endDate, $optParams);
47 |
48 | if (isset($report['rows'])) {
49 | printReportTableHeader($report['headers']);
50 | printReportTableRows($report['rows']);
51 | printReportTableFooter();
52 | } else {
53 | printNoResultForTable(count($report['headers']));
54 | }
55 | }
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/examples/adsensehost/examples/GenerateReportForHost.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class GenerateReportForHost extends BaseExample {
30 | public function render() {
31 | $startDate = $this->getSixMonthsBeforeNow();
32 | $endDate = $this->getNow();
33 | $optParams = array(
34 | 'metric' => array(
35 | 'PAGE_VIEWS', 'AD_REQUESTS', 'AD_REQUESTS_COVERAGE',
36 | 'CLICKS', 'AD_REQUESTS_CTR', 'COST_PER_CLICK', 'AD_REQUESTS_RPM',
37 | 'EARNINGS'),
38 | 'dimension' => 'DATE',
39 | 'sort' => '+DATE',
40 | 'filter' => array(
41 | 'AD_CLIENT_ID==' . HOST_AD_CLIENT_ID));
42 | // Retrieve report.
43 | $report = $this->adSenseHostService->reports
44 | ->generate($startDate, $endDate, $optParams);
45 |
46 | if (isset($report['rows'])) {
47 | printReportTableHeader($report['headers']);
48 | printReportTableRows($report['rows']);
49 | printReportTableFooter();
50 | } else {
51 | printNoResultForTable(count($report['headers']));
52 | }
53 | }
54 | }
55 |
56 |
--------------------------------------------------------------------------------
/examples/adsensehost/examples/GetAccountDataForExistingPublisher.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class GetAccountDataForExistingPublisher extends BaseExample {
29 | public function render() {
30 | $adClientId = PUBLISHER_AD_CLIENT_ID;
31 | $listClass = 'list';
32 | printListHeader($listClass);
33 | $pageToken = null;
34 | do {
35 | // Retrieve account list, and display it.
36 | $result = $this->adSenseHostService->accounts->listAccounts(
37 | array($adClientId));
38 | $accounts = $result['items'];
39 | if (isset($accounts)) {
40 | foreach ($accounts as $account) {
41 | $frmt = 'Account with ID "%s", name "%s" and status "%s" was found.';
42 | $content = sprintf($frmt, $account['id'], $account['name'],
43 | $account['status']);
44 | printListElement($content);
45 | }
46 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
47 | : null;
48 | } else {
49 | printNoResultForList();
50 | }
51 | } while ($pageToken);
52 | printListFooter();
53 | }
54 | }
55 |
56 |
--------------------------------------------------------------------------------
/examples/plus/style.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Google Inc.
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 | body {
16 | font-family: Arial,sans-serif;
17 | margin: auto;
18 | }
19 |
20 | .box {
21 | border: .5em solid #E3E9FF;
22 | -webkit-box-orient: vertical;
23 | -webkit-box-align: center;
24 | -moz-box-orient: vertical;
25 | -moz-box-align: center;
26 | display: block;
27 | box-orient: vertical;
28 | box-align: center;
29 | width: 350px;
30 | height: auto;
31 | margin: auto;
32 | padding: 10px;
33 | word-wrap: break-word;
34 | text-overflow: ellipsis;
35 | }
36 |
37 | .me {
38 | -webkit-box-flex: 1;
39 | -moz-box-flex: 1;
40 | box-flex: 1;
41 | width: 100px;
42 | }
43 |
44 | .activities {
45 | -webkit-box-flex: 2;
46 | -moz-box-flex: 2;
47 | box-flex: 2;
48 | width:100%;
49 | }
50 |
51 | .activity {
52 | margin: 10px;
53 | }
54 |
55 | header {
56 | color:#000;
57 | padding:2px 5px;
58 | font-size:100%;
59 | width: 400px;
60 | margin: auto;
61 | text-align: center
62 | }
63 |
64 | header h1.logo {
65 | margin:6px 0;
66 | padding:0;
67 | cursor:pointer;
68 | font-size:24px;
69 | line-height:20px;
70 | }
71 |
72 | .login {
73 | font-size: 200%;
74 | display: block;
75 | margin: auto;
76 | cursor: pointer;
77 | text-align: center;
78 | font-weight: bold;
79 | color: #2779AA;
80 | line-height: normal;
81 | }
82 |
83 | .logout {
84 | font-weight: normal;
85 | padding-top: -5px;
86 | margin-top: 0px;
87 | }
--------------------------------------------------------------------------------
/examples/prediction/style.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Google Inc.
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 | body {
16 | font-family: Arial,sans-serif;
17 | margin: auto;
18 | }
19 |
20 | .box {
21 | border: .5em solid #E3E9FF;
22 | -webkit-box-orient: vertical;
23 | -webkit-box-align: center;
24 | -moz-box-orient: vertical;
25 | -moz-box-align: center;
26 | display: block;
27 | box-orient: vertical;
28 | box-align: center;
29 | width: 350px;
30 | height: auto;
31 | margin: auto;
32 | padding: 10px;
33 | word-wrap: break-word;
34 | text-overflow: ellipsis;
35 | }
36 |
37 | .me {
38 | -webkit-box-flex: 1;
39 | -moz-box-flex: 1;
40 | box-flex: 1;
41 | width: 100px;
42 | }
43 |
44 | .activities {
45 | -webkit-box-flex: 2;
46 | -moz-box-flex: 2;
47 | box-flex: 2;
48 | width:100%;
49 | }
50 |
51 | .activity {
52 | margin: 10px;
53 | }
54 |
55 | header {
56 | color:#000;
57 | padding:2px 5px;
58 | font-size:100%;
59 | width: 400px;
60 | margin: auto;
61 | text-align: center
62 | }
63 |
64 | header h1.logo {
65 | margin:6px 0;
66 | padding:0;
67 | cursor:pointer;
68 | font-size:24px;
69 | line-height:20px;
70 | }
71 |
72 | .login {
73 | font-size: 200%;
74 | display: block;
75 | margin: auto;
76 | cursor: pointer;
77 | text-align: center;
78 | font-weight: bold;
79 | color: #2779AA;
80 | line-height: normal;
81 | }
82 |
83 | .logout {
84 | font-weight: normal;
85 | padding-top: -5px;
86 | margin-top: 0px;
87 | }
--------------------------------------------------------------------------------
/examples/analytics/simple.php:
--------------------------------------------------------------------------------
1 | setApplicationName("Google Analytics PHP Starter Application");
8 |
9 | // Visit https://code.google.com/apis/console?api=analytics to generate your
10 | // client id, client secret, and to register your redirect uri.
11 | // $client->setClientId('insert_your_oauth2_client_id');
12 | // $client->setClientSecret('insert_your_oauth2_client_secret');
13 | // $client->setRedirectUri('insert_your_oauth2_redirect_uri');
14 | // $client->setDeveloperKey('insert_your_developer_key');
15 | $service = new Google_AnalyticsService($client);
16 |
17 | if (isset($_GET['logout'])) {
18 | unset($_SESSION['token']);
19 | }
20 |
21 | if (isset($_GET['code'])) {
22 | $client->authenticate();
23 | $_SESSION['token'] = $client->getAccessToken();
24 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
25 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
26 | }
27 |
28 | if (isset($_SESSION['token'])) {
29 | $client->setAccessToken($_SESSION['token']);
30 | }
31 |
32 | if ($client->getAccessToken()) {
33 | $props = $service->management_webproperties->listManagementWebproperties("~all");
34 | print "Web Properties
" . print_r($props, true) . "
";
35 |
36 | $accounts = $service->management_accounts->listManagementAccounts();
37 | print "Accounts
" . print_r($accounts, true) . "
";
38 |
39 | $segments = $service->management_segments->listManagementSegments();
40 | print "Segments
" . print_r($segments, true) . "
";
41 |
42 | $goals = $service->management_goals->listManagementGoals("~all", "~all", "~all");
43 | print "Segments
" . print_r($goals, true) . "
";
44 |
45 | $_SESSION['token'] = $client->getAccessToken();
46 | } else {
47 | $authUrl = $client->createAuthUrl();
48 | print "Connect Me!";
49 | }
--------------------------------------------------------------------------------
/examples/adsense/examples/GetAllUrlChannels.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class GetAllUrlChannels extends BaseExample {
30 | public function render() {
31 | $adClientId = AD_CLIENT_ID;
32 | $optParams['maxResults'] = AD_MAX_PAGE_SIZE;
33 | $listClass = 'list';
34 | printListHeader($listClass);
35 | $pageToken = null;
36 | do {
37 | $optParams['pageToken'] = $pageToken;
38 | // Retrieve URL channels list and display it.
39 | $result = $this->adSenseService->urlchannels
40 | ->listUrlchannels($adClientId, $optParams);
41 | $urlChannels = $result['items'];
42 | if (empty($urlChannels)) {
43 | foreach ($urlChannels as $urlChannel) {
44 | $format = 'URL channel with URL pattern "%s" was found.';
45 | $content = sprintf($format, $urlChannel['urlPattern']);
46 | printListElement($content);
47 | }
48 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
49 | : null;
50 | } else {
51 | printNoResultForList();
52 | }
53 | } while ($pageToken);
54 | printListFooter();
55 | }
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/examples/adexchangebuyer/htmlHelper.php:
--------------------------------------------------------------------------------
1 |
22 | */
23 |
24 | /**
25 | * Opens the HTML.
26 | * @param string $title the title of the page
27 | */
28 | function printHtmlHeader($title) {
29 | $htmlTitle = filter_var($title, FILTER_SANITIZE_SPECIAL_CHARS);
30 | print '';
31 | print '';
32 | print '' . $htmlTitle . '';
33 | print '';
34 | print '';
35 | }
36 |
37 | /**
38 | * Closes the HTML.
39 | */
40 | function printHtmlFooter() {
41 | print '';
42 | print '';
43 | }
44 |
45 | /**
46 | * Closes the HTML for samples.
47 | */
48 | function printSampleHtmlFooter() {
49 | print 'Go back to samples list';
50 | printHtmlFooter();
51 | }
52 |
53 | /**
54 | * Prints the index with links to the examples.
55 | * @param array $actions supported actions
56 | */
57 | function printExamplesIndex($actions) {
58 | print 'Select a sample from the list
';
59 | print '';
60 | foreach ($actions as $action) {
61 | require_once 'examples/' . $action . '.php';
62 | $class = ucfirst($action);
63 | printf('- %s
', $action,
64 | $class::getName());
65 | }
66 | print '
';
67 | }
68 |
--------------------------------------------------------------------------------
/examples/adexchangeseller/examples/GetAllUrlChannels.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class GetAllUrlChannels extends BaseExample {
30 | public function render() {
31 | $adClientId = AD_CLIENT_ID;
32 | $optParams['maxResults'] = AD_MAX_PAGE_SIZE;
33 | $listClass = 'list';
34 | printListHeader($listClass);
35 | $pageToken = null;
36 | do {
37 | $optParams['pageToken'] = $pageToken;
38 | // Retrieve URL channels list and display it.
39 | $result = $this->adExchangeSellerService->urlchannels
40 | ->listUrlchannels($adClientId, $optParams);
41 | $urlChannels = $result['items'];
42 | if (empty($urlChannels)) {
43 | foreach ($urlChannels as $urlChannel) {
44 | $format = 'URL channel with URL pattern "%s" was found.';
45 | $content = sprintf($format, $urlChannel['urlPattern']);
46 | printListElement($content);
47 | }
48 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
49 | : null;
50 | } else {
51 | printNoResultForList();
52 | }
53 | } while ($pageToken);
54 | printListFooter();
55 | }
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/src/auth/Google_LoginTicket.php:
--------------------------------------------------------------------------------
1 |
22 | */
23 | class Google_LoginTicket {
24 | const USER_ATTR = "id";
25 |
26 | // Information from id token envelope.
27 | private $envelope;
28 |
29 | // Information from id token payload.
30 | private $payload;
31 |
32 | /**
33 | * Creates a user based on the supplied token.
34 | *
35 | * @param string $envelope Header from a verified authentication token.
36 | * @param string $payload Information from a verified authentication token.
37 | */
38 | public function __construct($envelope, $payload) {
39 | $this->envelope = $envelope;
40 | $this->payload = $payload;
41 | }
42 |
43 | /**
44 | * Returns the numeric identifier for the user.
45 | * @throws Google_AuthException
46 | * @return
47 | */
48 | public function getUserId() {
49 | if (array_key_exists(self::USER_ATTR, $this->payload)) {
50 | return $this->payload[self::USER_ATTR];
51 | }
52 | throw new Google_AuthException("No user_id in token");
53 | }
54 |
55 | /**
56 | * Returns attributes from the login ticket. This can contain
57 | * various information about the user session.
58 | * @return array
59 | */
60 | public function getAttributes() {
61 | return array("envelope" => $this->envelope, "payload" => $this->payload);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/examples/adsense/examples/GetAllAdUnits.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class GetAllAdUnits extends BaseExample {
30 | public function render() {
31 | $adClientId = AD_CLIENT_ID;
32 | $optParams['maxResults'] = AD_MAX_PAGE_SIZE;
33 | $listClass = 'list';
34 | printListHeader($listClass);
35 | $pageToken = null;
36 | do {
37 | $optParams['pageToken'] = $pageToken;
38 | // Retrieve ad unit list, and display it.
39 | $result = $this->adSenseService->adunits
40 | ->listAdunits($adClientId, $optParams);
41 | if (isset($result['items'])) {
42 | $adUnits = $result['items'];
43 | foreach ($adUnits as $adUnit) {
44 | $format =
45 | 'Ad unit with code "%s", name "%s" and status "%s" was found.';
46 | $content = sprintf(
47 | $format, $adUnit['code'], $adUnit['name'], $adUnit['status']);
48 | printListElement($content);
49 | }
50 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
51 | : null;
52 | } else {
53 | printNoResultForList();
54 | }
55 | } while ($pageToken);
56 | printListFooter();
57 | }
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/examples/adexchangeseller/examples/GetAllAdUnits.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class GetAllAdUnits extends BaseExample {
30 | public function render() {
31 | $adClientId = AD_CLIENT_ID;
32 | $optParams['maxResults'] = AD_MAX_PAGE_SIZE;
33 | $listClass = 'list';
34 | printListHeader($listClass);
35 | $pageToken = null;
36 | do {
37 | $optParams['pageToken'] = $pageToken;
38 | // Retrieve ad unit list, and display it.
39 | $result = $this->adExchangeSellerService->adunits
40 | ->listAdunits($adClientId, $optParams);
41 | if (isset($result['items'])) {
42 | $adUnits = $result['items'];
43 | foreach ($adUnits as $adUnit) {
44 | $format =
45 | 'Ad unit with code "%s", name "%s" and status "%s" was found.';
46 | $content = sprintf(
47 | $format, $adUnit['code'], $adUnit['name'], $adUnit['status']);
48 | printListElement($content);
49 | }
50 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
51 | : null;
52 | } else {
53 | printNoResultForList();
54 | }
55 | } while ($pageToken);
56 | printListFooter();
57 | }
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/examples/adexchangeseller/examples/GetAllSavedReports.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class GetAllSavedReports extends BaseExample {
29 | public function render() {
30 | $optParams['maxResults'] = AD_MAX_PAGE_SIZE;
31 | $listClass = 'saved reports';
32 | printListHeader($listClass);
33 | $pageToken = null;
34 | do {
35 | $optParams['pageToken'] = $pageToken;
36 | // Retrieve saved report list, and display it.
37 | $result = $this->adExchangeSellerService->reports_saved
38 | ->listReportsSaved($optParams);
39 | $savedReports = $result['items'];
40 | if (empty($savedReports)) {
41 | foreach ($savedReports as $savedReport) {
42 | $content = array();
43 | $mainFormat = 'Saved report with name "%s" and ID "%s" was found.';
44 | $content[] = sprintf(
45 | $mainFormat, $savedReport['name'], $savedReport['id']);
46 | printListElementForClients($content);
47 | }
48 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
49 | : null;
50 | } else {
51 | printNoResultForList();
52 | }
53 | } while ($pageToken);
54 | printListFooter();
55 | }
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/examples/adsense/examples/GenerateTableChart.php:
--------------------------------------------------------------------------------
1 |
25 | */
26 | class GenerateTableChart extends BaseExample {
27 | public function render() {
28 | $startDate = $this->getSixMonthsBeforeNow();
29 | $endDate = $this->getNow();
30 | $optParams = array(
31 | 'metric' => array('AD_REQUESTS', 'MATCHED_AD_REQUESTS',
32 | 'INDIVIDUAL_AD_IMPRESSIONS'),
33 | 'dimension' => array('AD_CLIENT_ID'),
34 | 'sort' => 'AD_CLIENT_ID'
35 | );
36 | // Retrieve report.
37 | $report = $this->adSenseService->reports
38 | ->generate($startDate, $endDate, $optParams);
39 | $data = $report['rows'];
40 | // We need to convert the metrics to numeric values for the chart.
41 | foreach ($data as &$row) {
42 | $row[1] = (int)$row[1];
43 | $row[2] = (int)$row[2];
44 | $row[3] = (int)$row[3];
45 | }
46 | $data = json_encode($data);
47 | $columns = array(
48 | array('string', 'Ad client id'),
49 | array('number', 'Ad requests'),
50 | array('number', 'Matched ad requests'),
51 | array('number', 'Individual ad impressions')
52 | );
53 | $type = 'Table';
54 | $options = json_encode(array());
55 | print generateChartHtml($data, $columns, $type, $options);
56 | }
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/examples/adsense/examples/GetAllSavedReports.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class GetAllSavedReports extends BaseExample {
29 | public function render() {
30 | $accountId = ACCOUNT_ID;
31 | $optParams['maxResults'] = AD_MAX_PAGE_SIZE;
32 | $listClass = 'saved reports';
33 | printListHeader($listClass);
34 | $pageToken = null;
35 | do {
36 | $optParams['pageToken'] = $pageToken;
37 | // Retrieve saved report list, and display it.
38 | $result = $this->adSenseService->accounts_reports_saved
39 | ->listAccountsReportsSaved($accountId, $optParams);
40 | $savedReports = $result['items'];
41 | if (empty($savedReports)) {
42 | foreach ($savedReports as $savedReport) {
43 | $content = array();
44 | $mainFormat = 'Saved report with name "%s" and ID "%s" was found.';
45 | $content[] = sprintf(
46 | $mainFormat, $savedReport['name'], $savedReport['id']);
47 | printListElementForClients($content);
48 | }
49 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
50 | : null;
51 | } else {
52 | printNoResultForList();
53 | }
54 | } while ($pageToken);
55 | printListFooter();
56 | }
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/examples/urlshortener/style.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2011 Google Inc.
3 | * Licensed under the Apache License, Version 2.0 (the "License");
4 | * you may not use this file except in compliance with the License.
5 | * You may obtain a copy of the License at
6 | *
7 | * http://www.apache.org/licenses/LICENSE-2.0
8 | *
9 | * Unless required by applicable law or agreed to in writing, software
10 | * distributed under the License is distributed on an "AS IS" BASIS,
11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | * See the License for the specific language governing permissions and
13 | * limitations under the License.
14 | */
15 |
16 | body {
17 | font-family: Arial,sans-serif;
18 | margin: auto;
19 | white-space: nowrap;
20 | }
21 |
22 | .box {
23 | border: .5em solid #E3E9FF;
24 | -webkit-box-orient: vertical;
25 | -webkit-box-align: center;
26 |
27 | -moz-box-orient: vertical;
28 | -moz-box-align: center;
29 |
30 | display: block;
31 | box-orient: vertical;
32 | box-align: center;
33 |
34 | width: 400px;
35 | height: auto;
36 |
37 | margin: auto;
38 | padding: 10px;
39 | }
40 |
41 | .request {
42 | -webkit-box-flex: 1;
43 | -moz-box-flex: 1;
44 | box-flex: 1;
45 | }
46 |
47 | .result {
48 | -webkit-box-flex: 2;
49 | -moz-box-flex: 2;
50 | box-flex: 2;
51 | }
52 |
53 | header {
54 | color:#000;
55 | padding:2px 5px;
56 | font-size:100%;
57 | margin: auto;
58 | text-align: center
59 | }
60 |
61 | header h1.logo {
62 | margin:6px 0;
63 | padding:0;
64 | font-size:24px;
65 | line-height:20px;
66 | text-align: center
67 | }
68 |
69 | .login {
70 | font-size: 200%;
71 | display: block;
72 | margin: auto;
73 | cursor: pointer;
74 | text-align: center;
75 | font-weight: bold;
76 | color: #2779AA;
77 | line-height: normal;
78 | }
79 |
80 | .logout {
81 | font-weight: normal;
82 | margin-top: 0;
83 | }
84 |
85 | .url {
86 | color: #019;
87 | font-size: 100%;
88 | vertical-align: middle;
89 | padding: 1px;
90 | background-color: white;
91 | border: 1px inset;
92 | cursor: auto;
93 | margin: 0;
94 | text-indent: 0;
95 | display: inline-block;
96 | }
--------------------------------------------------------------------------------
/examples/adsense/examples/GetAllSavedAdStyles.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class GetAllSavedAdStyles extends BaseExample {
29 | public function render() {
30 | $accountId = ACCOUNT_ID;
31 | $optParams['maxResults'] = AD_MAX_PAGE_SIZE;
32 | $listClass = 'saved ad styles';
33 | printListHeader($listClass);
34 | $pageToken = null;
35 | do {
36 | $optParams['pageToken'] = $pageToken;
37 | // Retrieve saved ad style list, and display it.
38 | $result = $this->adSenseService->accounts_savedadstyles
39 | ->listAccountsSavedadstyles($accountId, $optParams);
40 | $savedAdStyles = $result['items'];
41 | if (empty($savedAdStyles)) {
42 | foreach ($savedAdStyles as $savedAdStyle) {
43 | $content = array();
44 | $mainFormat = 'Saved ad style with name "%s" and ID "%s" was found.';
45 | $content[] = sprintf(
46 | $mainFormat, $savedAdStyle['name'], $savedAdStyle['id']);
47 | printListElementForClients($content);
48 | }
49 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
50 | : null;
51 | } else {
52 | printNoResultForList();
53 | }
54 | } while ($pageToken);
55 | printListFooter();
56 | }
57 | }
58 |
59 |
--------------------------------------------------------------------------------
/examples/adsensehost/examples/UpdateAdUnitOnPublisher.php:
--------------------------------------------------------------------------------
1 |
33 | */
34 | class UpdateAdUnitOnPublisher extends BaseExample {
35 | public function render() {
36 | $accountId = PUBLISHER_ACCOUNT_ID;
37 | $adClientId = PUBLISHER_AD_CLIENT_ID;
38 | $adUnitId = PUBLISHER_AD_UNIT_ID;
39 |
40 | $adUnit = new Google_AdUnit();
41 | $contentAdsSettings = new Google_AdUnitContentAdsSettings();
42 | $customStyle = new Google_AdStyle();
43 | $colors = new Google_AdStyleColors();
44 | $colors->setText('ff0000');
45 | $customStyle->setColors($colors);
46 | $adUnit->setCustomStyle($customStyle);
47 |
48 | // Retrieve custom channels list, and display it.
49 | $result = $this->adSenseHostService->accounts_adunits
50 | ->patch($accountId, $adClientId, $adUnitId, $adUnit);
51 | $mainFormat = 'Ad unit with ID "%s" was updated with text color "%s".';
52 | $content = sprintf($mainFormat, $result['id'],
53 | $result['customStyle']['colors']['text']);
54 | print $content;
55 | }
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/src/auth/Google_PemVerifier.php:
--------------------------------------------------------------------------------
1 |
22 | */
23 | class Google_PemVerifier extends Google_Verifier {
24 | private $publicKey;
25 |
26 | /**
27 | * Constructs a verifier from the supplied PEM-encoded certificate.
28 | *
29 | * $pem: a PEM encoded certificate (not a file).
30 | * @param $pem
31 | * @throws Google_AuthException
32 | * @throws Google_Exception
33 | */
34 | function __construct($pem) {
35 | if (!function_exists('openssl_x509_read')) {
36 | throw new Google_Exception('Google API PHP client needs the openssl PHP extension');
37 | }
38 | $this->publicKey = openssl_x509_read($pem);
39 | if (!$this->publicKey) {
40 | throw new Google_AuthException("Unable to parse PEM: $pem");
41 | }
42 | }
43 |
44 | function __destruct() {
45 | if ($this->publicKey) {
46 | openssl_x509_free($this->publicKey);
47 | }
48 | }
49 |
50 | /**
51 | * Verifies the signature on data.
52 | *
53 | * Returns true if the signature is valid, false otherwise.
54 | * @param $data
55 | * @param $signature
56 | * @throws Google_AuthException
57 | * @return bool
58 | */
59 | function verify($data, $signature) {
60 | $status = openssl_verify($data, $signature, $this->publicKey, "sha256");
61 | if ($status === -1) {
62 | throw new Google_AuthException('Signature verification error: ' . openssl_error_string());
63 | }
64 | return $status === 1;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/examples/adsense/BaseExample.php:
--------------------------------------------------------------------------------
1 |
29 | */
30 | abstract class BaseExample {
31 | protected $adSenseService;
32 | protected $dateFormat = 'Y-m-d';
33 |
34 | /**
35 | * Inject the dependency.
36 | * @param Google_AdsenseService $adSenseService an authenticated instance
37 | * of Google_AdsenseService
38 | */
39 | public function __construct(Google_AdsenseService $adSenseService) {
40 | $this->adSenseService = $adSenseService;
41 | }
42 |
43 | /**
44 | * Get the date for the instant of the call.
45 | * @return string the date in the format expressed by $this->dateFormat
46 | */
47 | protected function getNow() {
48 | $now = new DateTime();
49 | return $now->format($this->dateFormat);
50 | }
51 |
52 | /**
53 | * Get the date six month before the instant of the call.
54 | * @return string the date in the format expressed by $this->dateFormat
55 | */
56 | protected function getSixMonthsBeforeNow() {
57 | $sixMonthsAgo = new DateTime('-6 months');
58 | return $sixMonthsAgo->format($this->dateFormat);
59 | }
60 |
61 | /**
62 | * Implemented in the specific example class.
63 | */
64 | abstract public function render();
65 |
66 | }
67 |
68 |
--------------------------------------------------------------------------------
/examples/adsensehost/examples/GetAllUrlChannelsForHost.php:
--------------------------------------------------------------------------------
1 |
28 | * @author Silvano Luciani
29 | */
30 | class GetAllUrlChannelsForHost extends BaseExample {
31 | public function render() {
32 | $adClientId = HOST_AD_CLIENT_ID;
33 | $optParams['maxResults'] = MAX_PAGE_SIZE;
34 | $listClass = 'list';
35 | printListHeader($listClass);
36 | $pageToken = null;
37 | do {
38 | $optParams['pageToken'] = $pageToken;
39 | // Retrieve URL channels list and display it.
40 | $result = $this->adSenseHostService->urlchannels
41 | ->listUrlchannels($adClientId, $optParams);
42 | $urlChannels = $result['items'];
43 | if (isset($urlChannels)) {
44 | foreach ($urlChannels as $urlChannel) {
45 | $format = 'URL channel with ID "%s" and URL pattern "%s" was found.';
46 | $content = sprintf($format, $urlChannel['id'],
47 | $urlChannel['urlPattern']);
48 | printListElement($content);
49 | }
50 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
51 | : null;
52 | } else {
53 | printNoResultForList();
54 | }
55 | } while ($pageToken);
56 | printListFooter();
57 | }
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/examples/adexchangebuyer/examples/UpdateAccount.php:
--------------------------------------------------------------------------------
1 | 'account_id',
37 | 'display' => 'Account id to update',
38 | 'required' => true),
39 | array('name' => 'cookie_matching_url',
40 | 'display' => 'New cookie matching URL',
41 | 'required' => true));
42 | }
43 |
44 | /**
45 | * (non-PHPdoc)
46 | * @see BaseExample::run()
47 | */
48 | public function run() {
49 | $values = $this->formValues;
50 | $account = new Google_Account();
51 | $account->setId($values['account_id']);
52 | $account->setCookieMatchingUrl($values['cookie_matching_url']);
53 |
54 | $account = $this->service->accounts->patch($values['account_id'],
55 | $account);
56 | print 'Submitted account
';
57 | $this->printResult($account);
58 | }
59 |
60 | /**
61 | * (non-PHPdoc)
62 | * @see BaseExample::getName()
63 | * @return string
64 | */
65 | public function getName() {
66 | return 'Update Account';
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/examples/adsense/examples/GetAllAdClients.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class GetAllAdClients extends BaseExample {
29 | public function render() {
30 | $optParams['maxResults'] = AD_MAX_PAGE_SIZE;
31 | $listClass = 'clients';
32 | printListHeader($listClass);
33 | $pageToken = null;
34 | do {
35 | $optParams['pageToken'] = $pageToken;
36 | // Retrieve ad client list, and display it.
37 | $result = $this->adSenseService->adclients->listAdclients($optParams);
38 | $adClients = $result['items'];
39 | if (isset($adClients)) {
40 | foreach ($adClients as $adClient) {
41 | $content = array();
42 | $mainFormat = 'Ad client for product "%s" with ID "%s" was found.';
43 | $firstNestedFormat = 'Supports reporting: %s';
44 | $content[] = sprintf(
45 | $mainFormat, $adClient['productCode'], $adClient['id']);
46 | $reporting = $adClient['supportsReporting'] ? 'Yes' : 'No';
47 | $content[] = sprintf($firstNestedFormat, $reporting);
48 | printListElementForClients($content);
49 | }
50 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
51 | : null;
52 | } else {
53 | printNoResultForList();
54 | }
55 | } while ($pageToken);
56 | printListFooter();
57 | }
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/examples/adsense/examples/GenerateLineChart.php:
--------------------------------------------------------------------------------
1 |
25 | */
26 | class GenerateLineChart extends BaseExample {
27 | public function render() {
28 | $startDate = $this->getSixMonthsBeforeNow();
29 | $endDate = $this->getNow();
30 | $optParams = array(
31 | 'metric' => array('PAGE_VIEWS', 'AD_REQUESTS', 'MATCHED_AD_REQUESTS',
32 | 'INDIVIDUAL_AD_IMPRESSIONS'),
33 | 'dimension' => array('MONTH'),
34 | 'sort' => 'MONTH'
35 | );
36 | // Retrieve report.
37 | $report = $this->adSenseService->reports
38 | ->generate($startDate, $endDate, $optParams);
39 | $data = $report['rows'];
40 | // We need to convert the metrics to numeric values for the chart.
41 | foreach ($data as &$row) {
42 | $row[1] = (int)$row[1];
43 | $row[2] = (int)$row[2];
44 | $row[3] = (int)$row[3];
45 | $row[4] = (int)$row[4];
46 | }
47 | $data = json_encode($data);
48 | $columns = array(
49 | array('string', 'Month'),
50 | array('number', 'Page views'),
51 | array('number', 'Ad requests'),
52 | array('number', 'Matched ad requests'),
53 | array('number', 'Individual ad impressions')
54 | );
55 | $type = 'LineChart';
56 | $options = json_encode(
57 | array('title' => 'Performances per month')
58 | );
59 | print generateChartHtml($data, $columns, $type, $options);
60 | }
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/examples/adsense/examples/GenerateColumnChart.php:
--------------------------------------------------------------------------------
1 |
25 | */
26 | class GenerateColumnChart extends BaseExample {
27 | public function render() {
28 | $startDate = $this->getSixMonthsBeforeNow();
29 | $endDate = $this->getNow();
30 | $optParams = array(
31 | 'metric' => array('PAGE_VIEWS', 'AD_REQUESTS', 'MATCHED_AD_REQUESTS',
32 | 'INDIVIDUAL_AD_IMPRESSIONS'),
33 | 'dimension' => array('MONTH'),
34 | 'sort' => 'MONTH'
35 | );
36 | // Retrieve report.
37 | $report = $this->adSenseService->reports
38 | ->generate($startDate, $endDate, $optParams);
39 | $data = $report['rows'];
40 | // We need to convert the metrics to numeric values for the chart.
41 | foreach ($data as &$row) {
42 | $row[1] = (int)$row[1];
43 | $row[2] = (int)$row[2];
44 | $row[3] = (int)$row[3];
45 | $row[4] = (int)$row[4];
46 | }
47 | $data = json_encode($data);
48 | $columns = array(
49 | array('string', 'Month'),
50 | array('number', 'Page views'),
51 | array('number', 'Ad requests'),
52 | array('number', 'Matched ad requests'),
53 | array('number', 'Individual ad impressions')
54 | );
55 | $type = 'ColumnChart';
56 | $options = json_encode(
57 | array('title' => 'Performances per month')
58 | );
59 | print generateChartHtml($data, $columns, $type, $options);
60 | }
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/examples/adsensehost/examples/GenerateReportForPublisher.php:
--------------------------------------------------------------------------------
1 |
32 | */
33 | class GenerateReportForPublisher extends BaseExample {
34 | public function render() {
35 | $startDate = $this->getSixMonthsBeforeNow();
36 | $endDate = $this->getNow();
37 | $optParams = array(
38 | 'metric' => array(
39 | 'PAGE_VIEWS', 'AD_REQUESTS', 'AD_REQUESTS_COVERAGE',
40 | 'CLICKS', 'AD_REQUESTS_CTR', 'COST_PER_CLICK', 'AD_REQUESTS_RPM',
41 | 'EARNINGS'),
42 | 'dimension' => 'DATE',
43 | 'sort' => '+DATE',
44 | 'filter' => array(
45 | 'AD_CLIENT_ID==' . PUBLISHER_AD_CLIENT_ID));
46 | // Retrieve report.
47 | $report = $this->adSenseHostService->accounts_reports
48 | ->generate(PUBLISHER_ACCOUNT_ID, $startDate, $endDate, $optParams);
49 |
50 | if (isset($report['rows'])) {
51 | printReportTableHeader($report['headers']);
52 | printReportTableRows($report['rows']);
53 | printReportTableFooter();
54 | } else {
55 | printNoResultForTable(count($report['headers']));
56 | }
57 | }
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/examples/adsensehost/examples/GetAllAdClientsForHost.php:
--------------------------------------------------------------------------------
1 |
27 | * @author Silvano Luciani
28 | */
29 | class GetAllAdClientsForHost extends BaseExample {
30 | public function render() {
31 | $optParams['maxResults'] = MAX_PAGE_SIZE;
32 | $listClass = 'clients';
33 | printListHeader($listClass);
34 | $pageToken = null;
35 | do {
36 | $optParams['pageToken'] = $pageToken;
37 | // Retrieve ad client list, and display it.
38 | $result = $this->adSenseHostService->adclients->listAdclients($optParams);
39 | $adClients = $result['items'];
40 | if (isset($adClients)) {
41 | foreach ($adClients as $adClient) {
42 | $content = array();
43 | $mainFormat = 'Ad client for product "%s" with ID "%s" was found.';
44 | $content[] = sprintf(
45 | $mainFormat, $adClient['productCode'], $adClient['id']);
46 | $reporting = $adClient['supportsReporting'] ? 'Yes' : 'No';
47 | $content[] = sprintf('Supports reporting: %s', $reporting);
48 | printListElementForClients($content);
49 | }
50 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
51 | : null;
52 | } else {
53 | printNoResultForList();
54 | }
55 | } while ($pageToken);
56 | printListFooter();
57 | }
58 | }
59 |
60 |
--------------------------------------------------------------------------------
/examples/plus/simple.php:
--------------------------------------------------------------------------------
1 | setApplicationName("Google+ PHP Starter Application");
8 |
9 | // Visit https://code.google.com/apis/console?api=plus to generate your
10 | // client id, client secret, and to register your redirect uri.
11 | // $client->setClientId('insert_your_oauth2_client_id');
12 | // $client->setClientSecret('insert_your_oauth2_client_secret');
13 | // $client->setRedirectUri('insert_your_oauth2_redirect_uri');
14 | // $client->setDeveloperKey('insert_your_developer_key');
15 | $plus = new Google_PlusService($client);
16 |
17 | if (isset($_GET['logout'])) {
18 | unset($_SESSION['token']);
19 | }
20 |
21 | if (isset($_GET['code'])) {
22 | if (strval($_SESSION['state']) !== strval($_GET['state'])) {
23 | die("The session state did not match.");
24 | }
25 | $client->authenticate();
26 | $_SESSION['token'] = $client->getAccessToken();
27 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
28 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
29 | }
30 |
31 | if (isset($_SESSION['token'])) {
32 | $client->setAccessToken($_SESSION['token']);
33 | }
34 |
35 | if ($client->getAccessToken()) {
36 | $me = $plus->people->get('me');
37 | print "Your Profile: " . print_r($me, true) . "
";
38 |
39 | $params = array('maxResults' => 100);
40 | $activities = $plus->activities->listActivities('me', 'public', $params);
41 | print "Your Activities: " . print_r($activities, true) . "
";
42 |
43 | $params = array(
44 | 'orderBy' => 'best',
45 | 'maxResults' => '20',
46 | );
47 | $results = $plus->activities->search('Google+ API', $params);
48 | foreach($results['items'] as $result) {
49 | print "Search Result: {$result['object']['content']}\n";
50 | }
51 |
52 | // The access token may have been updated lazily.
53 | $_SESSION['token'] = $client->getAccessToken();
54 | } else {
55 | $state = mt_rand();
56 | $client->setState($state);
57 | $_SESSION['state'] = $state;
58 |
59 | $authUrl = $client->createAuthUrl();
60 | print "Connect Me!";
61 | }
--------------------------------------------------------------------------------
/examples/adexchangeseller/examples/GetAllAdClients.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class GetAllAdClients extends BaseExample {
29 | public function render() {
30 | $optParams['maxResults'] = AD_MAX_PAGE_SIZE;
31 | $listClass = 'clients';
32 | printListHeader($listClass);
33 | $pageToken = null;
34 | do {
35 | $optParams['pageToken'] = $pageToken;
36 | // Retrieve ad client list, and display it.
37 | $result = $this->adExchangeSellerService->adclients
38 | ->listAdclients($optParams);
39 | $adClients = $result['items'];
40 | if (isset($adClients)) {
41 | foreach ($adClients as $adClient) {
42 | $content = array();
43 | $mainFormat = 'Ad client for product "%s" with ID "%s" was found.';
44 | $firstNestedFormat = 'Supports reporting: %s';
45 | $content[] = sprintf(
46 | $mainFormat, $adClient['productCode'], $adClient['id']);
47 | $reporting = $adClient['supportsReporting'] ? 'Yes' : 'No';
48 | $content[] = sprintf($firstNestedFormat, $reporting);
49 | printListElementForClients($content);
50 | }
51 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
52 | : null;
53 | } else {
54 | printNoResultForList();
55 | }
56 | } while ($pageToken);
57 | printListFooter();
58 | }
59 | }
60 |
61 |
--------------------------------------------------------------------------------
/examples/adsensehost/examples/GetAllAdUnitsForPublisher.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class GetAllAdUnitsForPublisher extends BaseExample {
30 | public function render() {
31 | $adClientId = PUBLISHER_AD_CLIENT_ID;
32 | $accountId = PUBLISHER_ACCOUNT_ID;
33 | $optParams['maxResults'] = MAX_PAGE_SIZE;
34 | $listClass = 'list';
35 | printListHeader($listClass);
36 | $pageToken = null;
37 | do {
38 | $optParams['pageToken'] = $pageToken;
39 | // Retrieve ad unit list, and display it.
40 | $result = $this->adSenseHostService->accounts_adunits
41 | ->listAccountsAdunits($accountId, $adClientId, $optParams);
42 | if (isset($result['items'])) {
43 | $adUnits = $result['items'];
44 | foreach ($adUnits as $adUnit) {
45 | $content = sprintf('Ad unit with ID "%s", code "%s", name "%s" and ' .
46 | 'status "%s" was found.',
47 | $adUnit['id'], $adUnit['code'], $adUnit['name'],
48 | $adUnit['status']);
49 | printListElement($content);
50 | }
51 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
52 | : null;
53 | } else {
54 | printNoResultForList();
55 | }
56 | } while ($pageToken);
57 | printListFooter();
58 | }
59 | }
60 |
61 |
--------------------------------------------------------------------------------
/examples/adexchangeseller/examples/GetAllAdUnitsForCustomChannel.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class GetAllAdUnitsForCustomChannel extends BaseExample {
30 | public function render() {
31 | $adClientId = AD_CLIENT_ID;
32 | $customChannelId = CUSTOM_CHANNEL_ID;
33 | $optParams['maxResults'] = AD_MAX_PAGE_SIZE;
34 | $listClass = 'list';
35 | printListHeader($listClass);
36 | $pageToken = null;
37 | do {
38 | $optParams['pageToken'] = $pageToken;
39 | // Retrieve ad unit list, and display it.
40 | $result = $this->adExchangeSellerService->customchannels_adunits
41 | ->listCustomchannelsAdunits($adClientId, $customChannelId);
42 | $adUnits = $result['items'];
43 | if (isset($adUnits)) {
44 | foreach ($adUnits as $adUnit) {
45 | $format =
46 | 'Ad unit with code "%s", name "%s" and status "%s" was found.';
47 | $content = sprintf(
48 | $format, $adUnit['code'], $adUnit['name'], $adUnit['status']);
49 | printListElement($content);
50 | }
51 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
52 | : null;
53 | } else {
54 | printNoResultForList();
55 | }
56 | } while ($pageToken);
57 | printListFooter();
58 | }
59 | }
60 |
61 |
--------------------------------------------------------------------------------
/examples/adsense/examples/GetAllAdClientsForAccount.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class GetAllAdClientsForAccount extends BaseExample {
29 | public function render() {
30 | $accountId = ACCOUNT_ID;
31 | $optParams['maxResults'] = AD_MAX_PAGE_SIZE;
32 | $listClass = 'clients';
33 | printListHeader($listClass);
34 | $pageToken = null;
35 | do {
36 | $optParams['pageToken'] = $pageToken;
37 | // Retrieve ad client list, and display it.
38 | $result = $this->adSenseService->accounts_adclients
39 | ->listAccountsAdclients($accountId, $optParams);
40 | $adClients = $result['items'];
41 | if (isset($adClients)) {
42 | foreach ($adClients as $adClient) {
43 | $content = array();
44 | $mainFormat = 'Ad client for product "%s" with ID "%s" was found.';
45 | $firstNestedFormat = 'Supports reporting: %s';
46 | $content[] = sprintf(
47 | $mainFormat, $adClient['productCode'], $adClient['id']);
48 | $reporting = $adClient['supportsReporting'] ? 'Yes' : 'No';
49 | $content[] = sprintf($firstNestedFormat, $reporting);
50 | printListElementForClients($content);
51 | }
52 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
53 | : null;
54 | } else {
55 | printNoResultForList();
56 | }
57 | } while ($pageToken);
58 | printListFooter();
59 | }
60 | }
61 |
62 |
--------------------------------------------------------------------------------
/examples/pagespeed/index.php:
--------------------------------------------------------------------------------
1 | setApplicationName("PageSpeedOnline_Example_App");
23 | $service = new Google_PagespeedonlineService($client);
24 |
25 | if (isset($_GET['url'])) {
26 | $result = $service->pagespeedapi->runpagespeed($_GET['url']);
27 | }
28 | ?>
29 |
30 |
31 |
32 |
33 | Google Page Speed Sample App
34 |
35 |
36 |
40 |
41 |
42 |
43 |
44 |
Summary
45 | got a PageSpeed Score of
(out of 100).
46 |
Title:
47 |
Score:
48 |
Number of Resources:
49 |
Number of Hosts:
50 |
Total Request Bytes:
51 |
Number of Static Resources:
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/examples/adsensehost/examples/GetAllCustomChannelsForHost.php:
--------------------------------------------------------------------------------
1 |
28 | * @author Silvano Luciani
29 | */
30 | class GetAllCustomChannelsForHost extends BaseExample {
31 | public function render() {
32 | $adClientId = HOST_AD_CLIENT_ID;
33 | $optParams['maxResults'] = MAX_PAGE_SIZE;
34 | $listClass = 'list';
35 | printListHeader($listClass);
36 | $pageToken = null;
37 | do {
38 | $optParams['pageToken'] = $pageToken;
39 | // Retrieve custom channels list, and display it.
40 | $result = $this->adSenseHostService->customchannels
41 | ->listCustomchannels($adClientId, $optParams);
42 | $customChannels = $result['items'];
43 | if (isset($customChannels)) {
44 | foreach ($customChannels as $customChannel) {
45 | $content = array();
46 | $mainFormat =
47 | 'Custom channel with ID "%s", code "%s" and name "%s" found.';
48 | $content[] = sprintf($mainFormat, $customChannel['id'],
49 | $customChannel['code'], $customChannel['name']);
50 | printListElementForClients($content);
51 | }
52 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
53 | : null;
54 | } else {
55 | printNoResultForList();
56 | }
57 | } while ($pageToken);
58 | printListFooter();
59 | }
60 | }
61 |
62 |
--------------------------------------------------------------------------------
/examples/adsense/examples/GetAccountTree.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class GetAccountTree extends BaseExample {
30 | public function render() {
31 | $accountId = ACCOUNT_ID;
32 | $optParams = array('tree' => true);
33 | // Retrieve account with sub accounts.
34 | $account = $this->adSenseService->accounts->get($accountId, $optParams);
35 | $data = array();
36 | $this->buildTree($account, $data, null);
37 | $data = json_encode($data);
38 | $columns = array(
39 | array('string', 'Account ID'),
40 | array('string', 'Parent'),
41 | array('number', 'Weight')
42 | );
43 | $type = 'TreeMap';
44 | $options = json_encode(
45 | array('title' => 'Account treemap')
46 | );
47 | print generateChartHtml($data, $columns, $type, $options);
48 | }
49 |
50 | /**
51 | * Builds the data structure to represent the tree from the API response.
52 | * @param array $account The response of the API
53 | * @param array $data The data structure that represent the tree
54 | * @param string $parent The parent for the current node
55 | */
56 | private function buildTree($account, &$data, $parent) {
57 | $data[] = array($account['name'], null, 1);
58 | if ($account['subAccounts']) {
59 | foreach($account['subAccounts'] as $subAccount) {
60 | $this->buildTree($subAccount, $data, $account['name']);
61 | }
62 | }
63 | }
64 | }
65 |
66 |
--------------------------------------------------------------------------------
/examples/adsense/examples/GetAllAdUnitsForCustomChannel.php:
--------------------------------------------------------------------------------
1 |
28 | */
29 | class GetAllAdUnitsForCustomChannel extends BaseExample {
30 | public function render() {
31 | $adClientId = AD_CLIENT_ID;
32 | $accountId = ACCOUNT_ID;
33 | $customChannelId = CUSTOM_CHANNEL_ID;
34 | $optParams['maxResults'] = AD_MAX_PAGE_SIZE;
35 | $listClass = 'list';
36 | printListHeader($listClass);
37 | $pageToken = null;
38 | do {
39 | $optParams['pageToken'] = $pageToken;
40 | // Retrieve ad unit list, and display it.
41 | $result = $this->adSenseService->accounts_customchannels_adunits
42 | ->listAccountsCustomchannelsAdunits(
43 | $accountId, $adClientId, $customChannelId);
44 | $adUnits = $result['items'];
45 | if (isset($adUnits)) {
46 | foreach ($adUnits as $adUnit) {
47 | $format =
48 | 'Ad unit with code "%s", name "%s" and status "%s" was found.';
49 | $content = sprintf(
50 | $format, $adUnit['code'], $adUnit['name'], $adUnit['status']);
51 | printListElement($content);
52 | }
53 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
54 | : null;
55 | } else {
56 | printNoResultForList();
57 | }
58 | } while ($pageToken);
59 | printListFooter();
60 | }
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/examples/adsense/examples/HandleAccountErrors.php:
--------------------------------------------------------------------------------
1 |
27 | */
28 | class HandleAccountErrors extends BaseExample {
29 | public function render() {
30 | $optParams['maxResults'] = AD_MAX_PAGE_SIZE;
31 | try {
32 | $result = $this->adSenseService->adclients->listAdclients($optParams);
33 |
34 | print 'The call succeeded. Please use an invalid, disapproved or '
35 | .'approval-pending AdSense account to test error handling.';
36 |
37 | // Handle a few known API errors. See full list at
38 | // https://developers.google.com/adsense/management/v1.1/reference/#errors
39 | } catch (Google_ServiceException $e) {
40 | foreach ($e->getErrors() as $error) {
41 | switch ($error['reason']) {
42 | case 'noAdSenseAccount':
43 | print 'Error handled! No AdSense account for this user.';
44 | break;
45 | case 'disapprovedAccount':
46 | print 'Error handled! This account is disapproved.';
47 | break;
48 | case 'accountPendingReview':
49 | print 'Error handled! This account is pending review.';
50 | break;
51 | default:
52 | // Unrecognized reason, so let's use the error message returned by
53 | // the API.
54 | print 'Unrecognized error, showing system message: ';
55 | print $error['message'];
56 | break;
57 | }
58 | }
59 | }
60 | }
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/examples/batch.php:
--------------------------------------------------------------------------------
1 | setApplicationName("Google+ PHP Starter Application");
24 | $plus = new Google_PlusService($client);
25 |
26 | // Visit https://code.google.com/apis/console?api=plus to generate your
27 | // client id, client secret, and to register your redirect uri.
28 | // $client->setClientId('insert_your_oauth2_client_id');
29 | // $client->setClientSecret('insert_your_oauth2_client_secret');
30 | // $client->setRedirectUri('insert_your_oauth2_redirect_uri');
31 | // $client->setDeveloperKey('insert_your_developer_key');
32 |
33 | if (isset($_GET['logout'])) {
34 | unset($_SESSION['token']);
35 | }
36 |
37 | if (isset($_GET['code'])) {
38 | $client->authenticate();
39 | $_SESSION['token'] = $client->getAccessToken();
40 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
41 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
42 | }
43 |
44 | if (isset($_SESSION['token'])) {
45 | $client->setAccessToken($_SESSION['token']);
46 | }
47 |
48 | if ($client->getAccessToken()) {
49 | $client->setUseBatch(true);
50 |
51 | $batch = new Google_BatchRequest();
52 | $batch->add($plus->people->get('me'), 'key1');
53 | $batch->add($plus->people->get('me'), 'key2');
54 | $result = $batch->execute();
55 | print "" . print_r($result, true) . "
";
56 |
57 | // The access token may have been updated lazily.
58 | $_SESSION['token'] = $client->getAccessToken();
59 | } else {
60 | $authUrl = $client->createAuthUrl();
61 | print "Connect Me!";
62 | }
63 |
--------------------------------------------------------------------------------
/examples/adexchangeseller/BaseExample.php:
--------------------------------------------------------------------------------
1 |
29 | * @author Sergio Gomes
30 | */
31 | abstract class BaseExample {
32 | protected $adExchangeSellerService;
33 | protected $dateFormat = 'Y-m-d';
34 |
35 | /**
36 | * Inject the dependency.
37 | * @param Google_AdExchangeSellerService $adExchangeSellerService an
38 | * authenticated instance of Google_AdExchangeSellerService
39 | */
40 | public function __construct(
41 | Google_AdExchangeSellerService $adExchangeSellerService) {
42 | $this->adExchangeSellerService = $adExchangeSellerService;
43 | }
44 |
45 | /**
46 | * Get the date for the instant of the call.
47 | * @return string the date in the format expressed by $this->dateFormat
48 | */
49 | protected function getNow() {
50 | $now = new DateTime();
51 | return $now->format($this->dateFormat);
52 | }
53 |
54 | /**
55 | * Get the date six month before the instant of the call.
56 | * @return string the date in the format expressed by $this->dateFormat
57 | */
58 | protected function getSixMonthsBeforeNow() {
59 | $sixMonthsAgo = new DateTime('-6 months');
60 | return $sixMonthsAgo->format($this->dateFormat);
61 | }
62 |
63 | /**
64 | * Implemented in the specific example class.
65 | */
66 | abstract public function render();
67 |
68 | }
69 |
70 |
--------------------------------------------------------------------------------
/examples/analytics/demo/storage.php:
--------------------------------------------------------------------------------
1 |
27 | * @author Silvano Luciani
28 | */
29 | class GetAllAdClientsForPublisher extends BaseExample {
30 | public function render() {
31 | $accountId = PUBLISHER_ACCOUNT_ID;
32 | $optParams['maxResults'] = MAX_PAGE_SIZE;
33 | $listClass = 'clients';
34 | printListHeader($listClass);
35 | $pageToken = null;
36 | do {
37 | $optParams['pageToken'] = $pageToken;
38 | // Retrieve ad client list, and display it.
39 | $result = $this->adSenseHostService->accounts_adclients
40 | ->listAccountsAdclients($accountId, $optParams);
41 | $adClients = $result['items'];
42 | if (isset($adClients)) {
43 | foreach ($adClients as $adClient) {
44 | $content = array();
45 | $mainFormat = 'Ad client for product "%s" with ID "%s" was found.';
46 | $firstNestedFormat = 'Supports reporting: %s';
47 | $content[] = sprintf(
48 | $mainFormat, $adClient['productCode'], $adClient['id']);
49 | $reporting = $adClient['supportsReporting'] ? 'Yes' : 'No';
50 | $content[] = sprintf($firstNestedFormat, $reporting);
51 | printListElementForClients($content);
52 | }
53 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken']
54 | : null;
55 | } else {
56 | printNoResultForList();
57 | }
58 | } while ($pageToken);
59 | printListFooter();
60 | }
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/test/plus/PlusTest.php:
--------------------------------------------------------------------------------
1 | setName('Google Plus API tests');
24 | $suite->addTestSuite('PlusTest');
25 | return $suite;
26 | }
27 | }
28 |
29 | class PlusTest extends BaseTest {
30 | /** @var Google_PlusService */
31 | public $plus;
32 | public function __construct() {
33 | parent::__construct();
34 | $this->plus = new Google_PlusService(BaseTest::$client);
35 | }
36 |
37 | public function testGetPerson() {
38 | $person = $this->plus->people->get("118051310819094153327");
39 | $this->assertArrayHasKey('kind', $person);
40 | $this->assertArrayHasKey('displayName', $person);
41 | $this->assertArrayHasKey('gender', $person);
42 | $this->assertArrayHasKey('id', $person);
43 | $this->assertArrayHasKey('urls', $person);
44 | $this->assertArrayHasKey('organizations', $person);
45 | }
46 |
47 | public function testListActivities() {
48 | $activities = $this->plus->activities
49 | ->listActivities("118051310819094153327", "public");
50 |
51 | $item = $activities['items'][0];
52 | $this->assertArrayHasKey('kind', $activities);
53 | $this->assertArrayHasKey('items', $activities);
54 | $this->assertArrayHasKey('actor', $item);
55 | $this->assertArrayHasKey('displayName', $item['actor']);
56 | $this->assertArrayHasKey('url', $item['actor']);
57 | $this->assertArrayHasKey('object', $item);
58 | $this->assertArrayHasKey('access', $item);
59 | $this->assertArrayHasKey('crosspostSource', $item);
60 | $this->assertArrayHasKey('provider', $item);
61 |
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/examples/adexchangebuyer/examples/GetCreative.php:
--------------------------------------------------------------------------------
1 | 'account_id',
37 | 'display' => 'Account id',
38 | 'required' => true),
39 | array('name' => 'ad_group_id',
40 | 'display' => 'Ad group id',
41 | 'required' => true),
42 | array('name' => 'buyer_creative_id',
43 | 'display' => 'Buyer creative id',
44 | 'required' => true));
45 | }
46 |
47 | /**
48 | * (non-PHPdoc)
49 | * @see BaseExample::run()
50 | */
51 | public function run() {
52 | $values = $this->formValues;
53 |
54 | try {
55 | $creative = $this->service->creatives->get($values['account_id'],
56 | $values['buyer_creative_id'], $values['ad_group_id']);
57 | print 'Found creative
';
58 | $this->printResult($creative);
59 | } catch (Google_Exception $ex) {
60 | if ($ex->getCode() == 404 || $ex->getCode() == 403) {
61 | print 'Creative not found or can\'t access creative
';
62 | } else {
63 | throw $ex;
64 | }
65 | }
66 | }
67 |
68 | /**
69 | * (non-PHPdoc)
70 | * @see BaseExample::getName()
71 | * @return string
72 | */
73 | public function getName() {
74 | return 'Get Creative';
75 | }
76 | }
77 |
78 |
--------------------------------------------------------------------------------
/examples/books/books_browser.css:
--------------------------------------------------------------------------------
1 | body {
2 | background-color: white;
3 | color: black;
4 | font-family: Arial, sans-serif;
5 | font-size: small;
6 | margin: 8px;
7 | margin-top: 3px;
8 | }
9 |
10 | .thumbnail img {
11 | border-color:black;
12 | border-style:solid;
13 | }
14 |
15 | table {
16 | border-collapse: collapse;
17 | }
18 |
19 | th, td {
20 | padding: 0;
21 | vertical-align: top;
22 | text-align: left;
23 | font-size: small;
24 | }
25 |
26 | a:link {
27 | color: #0000cc;
28 | }
29 |
30 | a:active {
31 | color: #cc0000;
32 | }
33 |
34 | a:visited {
35 | color: #551a8b;
36 | }
37 |
38 | h1 {
39 | font-size: x-large;
40 | margin-top: 0px;
41 | margin-bottom: 5px;
42 | }
43 |
44 | h2 {
45 | font-size: large;
46 | }
47 |
48 | form {
49 | display: inline;
50 | margin: 0;
51 | padding: 0;
52 | }
53 |
54 | .volumeList td {
55 | padding-bottom: 5px;
56 | padding-right: 5px;
57 | }
58 |
59 | #titleBar {
60 | border: 1px solid silver;
61 | background-color: #e5ecf9;
62 | font-size: large;
63 | font-weight: bold;
64 | margin: 0;
65 | padding: 0;
66 | padding-top: 5px;
67 | padding-bottom: 10px;
68 | padding-left: 10px;
69 | padding-right: 10px;
70 | margin-top: 5px;
71 | margin-bottom: 15px;
72 | }
73 |
74 | #titleText {
75 | float: left;
76 | }
77 |
78 | #mainSearchBox {
79 | background-color: #e5ecf9;
80 | border: 1px solid silver;
81 | width: 300;
82 | padding-top: 5px;
83 | padding-bottom: 10px;
84 | padding-left: 10px;
85 | padding-right: 10px;
86 | }
87 |
88 | #searchResults {
89 | width: 100%;
90 | }
91 |
92 | .volumeList td
93 | {
94 | border-top: 1px solid #aaaaaa;
95 | padding: 6px;
96 | }
97 |
98 | .thumbnail
99 | {
100 | height: 80px;
101 | padding: 3px;
102 | }
103 |
104 | .previewbutton
105 | {
106 | border: 0px;
107 | margin: 6px 0px 6px 0px;
108 | }
109 |
110 | #resultcell
111 | {
112 | padding-right: 20px;
113 | }
114 |
115 | #previewcell
116 | {
117 | border-left: 1px dotted #aaa;
118 | padding-left: 20px;
119 | display: none;
120 | padding-right: 20px;
121 | }
122 |
123 | #viewport {
124 | height: 500px;
125 | width: 100%;
126 | border: 1px solid #aaa;
127 | }
128 |
129 | /* Google Preview: Boilerplate styling */
130 | #viewport { font-size: 16px; line-height: 1; }
131 | #viewport img, #viewport table, #viewport div, #viewport td
132 | { border: 0; padding: 0; margin: 0; background: none }
133 | #viewport td { vertical-align: middle }
--------------------------------------------------------------------------------
/examples/tasks/index.php:
--------------------------------------------------------------------------------
1 | setClientId('insert_your_oauth2_client_id');
25 | // $client->setClientSecret('insert_your_oauth2_client_secret');
26 | // $client->setRedirectUri('insert_your_oauth2_redirect_uri');
27 | // $client->setApplicationName("Tasks_Example_App");
28 | $tasksService = new Google_TasksService($client);
29 |
30 | if (isset($_REQUEST['logout'])) {
31 | unset($_SESSION['access_token']);
32 | }
33 |
34 | if (isset($_SESSION['access_token'])) {
35 | $client->setAccessToken($_SESSION['access_token']);
36 | } else {
37 | $client->setAccessToken($client->authenticate($_GET['code']));
38 | $_SESSION['access_token'] = $client->getAccessToken();
39 | }
40 |
41 | if (isset($_GET['code'])) {
42 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
43 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
44 | }
45 | ?>
46 |
47 |
48 |
49 | Tasks API Sample
50 |
51 |
52 |
53 |
54 |
55 |
Tasks API Sample
56 |
57 | tasklists->listTasklists();
59 | foreach ($lists['items'] as $list) {
60 | print "
{$list['title']}
";
61 | $tasks = $tasksService->tasks->listTasks($list['id']);
62 | }
63 | ?>
64 |
65 |
66 |
67 |
68 | getAccessToken(); ?>
--------------------------------------------------------------------------------
/test/general/CacheTest.php:
--------------------------------------------------------------------------------
1 | set('foo', 'bar');
25 | $this->assertEquals($cache->get('foo'), 'bar');
26 |
27 | $cache->set('foo.1', 'bar.1');
28 | $this->assertEquals($cache->get('foo.1'), 'bar.1');
29 |
30 | $cache->set('foo', 'baz');
31 | $this->assertEquals($cache->get('foo'), 'baz');
32 |
33 | $cache->set('foo', null);
34 | $this->assertEquals($cache->get('foo'), null);
35 |
36 | $cache->set('1/2/3', 'bar');
37 | $this->assertEquals($cache->get('1/2/3'), 'bar');
38 |
39 | $obj = new stdClass();
40 | $obj->foo = 'bar';
41 | $cache->set('foo', $obj);
42 | $this->assertEquals($cache->get('foo'), $obj);
43 | }
44 |
45 | public function testDelete() {
46 | global $apiConfig;
47 | $apiConfig['ioFileCache_directory'] = '/tmp/google-api-php-client/tests';
48 | $cache = new Google_FileCache();
49 | $cache->set('foo', 'bar');
50 | $cache->delete('foo');
51 | $this->assertEquals($cache->get('foo'), false);
52 |
53 | $cache->set('foo.1', 'bar.1');
54 | $cache->delete('foo.1');
55 | $this->assertEquals($cache->get('foo.1'), false);
56 |
57 | $cache->set('foo', 'baz');
58 | $cache->delete('foo');
59 | $this->assertEquals($cache->get('foo'), false);
60 |
61 | $cache->set('foo', null);
62 | $cache->delete('foo');
63 | $this->assertEquals($cache->get('foo'), false);
64 |
65 | $obj = new stdClass();
66 | $obj->foo = 'bar';
67 | $cache->set('foo', $obj);
68 | $cache->delete('foo');
69 | $this->assertEquals($cache->get('foo'), false);
70 | }
71 | }
--------------------------------------------------------------------------------
/examples/adsensehost/BaseExample.php:
--------------------------------------------------------------------------------
1 |
29 | * @author Silvano Luciani
30 | */
31 | abstract class BaseExample {
32 | protected $adSenseHostService;
33 | protected $dateFormat = 'Y-m-d';
34 |
35 | /**
36 | * Inject the dependency.
37 | * @param Google_AdsensehostService $adSenseHostService an authenticated
38 | * instance of Google_AdsensehostService
39 | */
40 | public function __construct(Google_AdsensehostService $adSenseHostService) {
41 | $this->adSenseHostService = $adSenseHostService;
42 | }
43 |
44 | /**
45 | * Get the date for the instant of the call.
46 | * @return string the date in the format expressed by $this->dateFormat
47 | */
48 | protected function getNow() {
49 | $now = new DateTime();
50 | return $now->format($this->dateFormat);
51 | }
52 |
53 | /**
54 | * Get the date six month before the instant of the call.
55 | * @return string the date in the format expressed by $this->dateFormat
56 | */
57 | protected function getSixMonthsBeforeNow() {
58 | $sixMonthsAgo = new DateTime('-6 months');
59 | return $sixMonthsAgo->format($this->dateFormat);
60 | }
61 |
62 | /**
63 | * Returns a unique value to append to various properties in the samples.
64 | * @return string unique value
65 | */
66 | protected function getUniqueName() {
67 | $now = new DateTime();
68 | return $now->format('YmdHisu');
69 | }
70 |
71 | /**
72 | * Implemented in the specific example class.
73 | */
74 | abstract public function render();
75 |
76 | }
77 |
78 |
--------------------------------------------------------------------------------
/src/auth/Google_P12Signer.php:
--------------------------------------------------------------------------------
1 |
24 | */
25 | class Google_P12Signer extends Google_Signer {
26 | // OpenSSL private key resource
27 | private $privateKey;
28 |
29 | // Creates a new signer from a .p12 file.
30 | function __construct($p12, $password) {
31 | if (!function_exists('openssl_x509_read')) {
32 | throw new Exception(
33 | 'The Google PHP API library needs the openssl PHP extension');
34 | }
35 |
36 | // This throws on error
37 | $certs = array();
38 | if (!openssl_pkcs12_read($p12, $certs, $password)) {
39 | throw new Google_AuthException("Unable to parse the p12 file. " .
40 | "Is this a .p12 file? Is the password correct? OpenSSL error: " .
41 | openssl_error_string());
42 | }
43 | // TODO(beaton): is this part of the contract for the openssl_pkcs12_read
44 | // method? What happens if there are multiple private keys? Do we care?
45 | if (!array_key_exists("pkey", $certs) || !$certs["pkey"]) {
46 | throw new Google_AuthException("No private key found in p12 file.");
47 | }
48 | $this->privateKey = openssl_pkey_get_private($certs["pkey"]);
49 | if (!$this->privateKey) {
50 | throw new Google_AuthException("Unable to load private key in ");
51 | }
52 | }
53 |
54 | function __destruct() {
55 | if ($this->privateKey) {
56 | openssl_pkey_free($this->privateKey);
57 | }
58 | }
59 |
60 | function sign($data) {
61 | if(version_compare(PHP_VERSION, '5.3.0') < 0) {
62 | throw new Google_AuthException(
63 | "PHP 5.3.0 or higher is required to use service accounts.");
64 | }
65 | if (!openssl_sign($data, $signature, $this->privateKey, "sha256")) {
66 | throw new Google_AuthException("Unable to sign data");
67 | }
68 | return $signature;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/examples/contacts/simple.php:
--------------------------------------------------------------------------------
1 | setApplicationName('Google Contacts PHP Sample');
23 | $client->setScopes("http://www.google.com/m8/feeds/");
24 | // Documentation: http://code.google.com/apis/gdata/docs/2.0/basics.html
25 | // Visit https://code.google.com/apis/console?api=contacts to generate your
26 | // oauth2_client_id, oauth2_client_secret, and register your oauth2_redirect_uri.
27 | // $client->setClientId('insert_your_oauth2_client_id');
28 | // $client->setClientSecret('insert_your_oauth2_client_secret');
29 | // $client->setRedirectUri('insert_your_redirect_uri');
30 | // $client->setDeveloperKey('insert_your_developer_key');
31 |
32 | if (isset($_GET['code'])) {
33 | $client->authenticate();
34 | $_SESSION['token'] = $client->getAccessToken();
35 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
36 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
37 | }
38 |
39 | if (isset($_SESSION['token'])) {
40 | $client->setAccessToken($_SESSION['token']);
41 | }
42 |
43 | if (isset($_REQUEST['logout'])) {
44 | unset($_SESSION['token']);
45 | $client->revokeToken();
46 | }
47 |
48 | if ($client->getAccessToken()) {
49 | $req = new Google_HttpRequest("https://www.google.com/m8/feeds/contacts/default/full");
50 | $val = $client->getIo()->authenticatedRequest($req);
51 |
52 | // The contacts api only returns XML responses.
53 | $response = json_encode(simplexml_load_string($val->getResponseBody()));
54 | print "" . print_r(json_decode($response, true), true) . "
";
55 |
56 | // The access token may have been updated lazily.
57 | $_SESSION['token'] = $client->getAccessToken();
58 | } else {
59 | $auth = $client->createAuthUrl();
60 | }
61 |
62 | if (isset($auth)) {
63 | print "Connect Me!";
64 | } else {
65 | print "Logout";
66 | }
--------------------------------------------------------------------------------
/examples/affiliateNetwork/index.php:
--------------------------------------------------------------------------------
1 | setApplicationName("Google GAN PHP Starter Application");
24 | // Visit https://code.google.com/apis/console?api=gan to generate your
25 | // oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri.
26 | // $client->setClientId('insert_your_oauth2_client_id');
27 | // $client->setClientSecret('insert_your_oauth2_client_secret');
28 | // $client->setRedirectUri('insert_your_oauth2_redirect_uri');
29 | // $client->setDeveloperKey('insert_your_simple_api_key');
30 | $gan = new Google_GanService($client);
31 |
32 | if (isset($_REQUEST['logout'])) {
33 | unset($_SESSION['access_token']);
34 | }
35 |
36 | if (isset($_GET['code'])) {
37 | $client->authenticate();
38 | $_SESSION['access_token'] = $client->getAccessToken();
39 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
40 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
41 | }
42 |
43 | if (isset($_SESSION['access_token'])) {
44 | $client->setAccessToken($_SESSION['access_token']);
45 | }
46 |
47 | if ($client->getAccessToken()) {
48 | $publishers = $gan->publishers->listPublishers("advertisers", "INSERT_ROLE_ID" /* The ID of the requesting advertiser or publisher */);
49 | $advertisers = $gan->advertisers->listAdvertisers("publishers", "INSERT_ROLE_ID" /* The ID of the requesting advertiser or publisher */);
50 | print "" . print_r($publishers, true) . "
";
51 | print "" . print_r($advertisers, true) . "
";
52 |
53 | // The access token may have been updated lazily.
54 | $_SESSION['access_token'] = $client->getAccessToken();
55 | } else {
56 | $authUrl = $client->createAuthUrl();
57 | }
58 |
59 | if(isset($authUrl)) {
60 | print "Connect Me!";
61 | } else {
62 | print "Logout";
63 | }
--------------------------------------------------------------------------------
/test/tasks/TasksTest.php:
--------------------------------------------------------------------------------
1 | taskService = new Google_TasksService(BaseTest::$client);
27 | }
28 |
29 | public function testInsertTask() {
30 | $list = $this->createTaskList('List: ' . __METHOD__);
31 | $task = $this->createTask('Task: '.__METHOD__, $list['id']);
32 | $this->assertIsTask($task);
33 | }
34 |
35 | public function testGetTask() {
36 | $tasks = $this->taskService->tasks;
37 | $list = $this->createTaskList('List: ' . __METHOD__);
38 | $task = $this->createTask('Task: '. __METHOD__, $list['id']);
39 |
40 | $task = $tasks->get($list['id'], $task['id']);
41 | $this->assertIsTask($task);
42 | }
43 |
44 | public function testListTask() {
45 | $tasks = $this->taskService->tasks;
46 | $list = $this->createTaskList('List: ' . __METHOD__);
47 |
48 | for ($i=0; $i<4; $i++) {
49 | $this->createTask("Task: $i ".__METHOD__, $list['id']);
50 | }
51 |
52 | $tasksArray = $tasks->listTasks($list['id']);
53 | $this->assertTrue(sizeof($tasksArray) > 1);
54 | foreach ($tasksArray['items'] as $task) {
55 | $this->assertIsTask($task);
56 | }
57 | }
58 |
59 | private function createTaskList($name) {
60 | $list = new Google_TaskList();
61 | $list->title = $name;
62 | return $this->taskService->tasklists->insert($list);
63 | }
64 |
65 | private function createTask($title, $listId) {
66 | $tasks = $this->taskService->tasks;
67 | $task = new Google_Task();
68 | $task->title = $title;
69 | return $tasks->insert($listId, $task);
70 | }
71 |
72 | private function assertIsTask($task) {
73 | $this->assertArrayHasKey('title', $task);
74 | $this->assertArrayHasKey('kind', $task);
75 | $this->assertArrayHasKey('id', $task);
76 | $this->assertArrayHasKey('position', $task);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/examples/prediction/serviceAccount.php:
--------------------------------------------------------------------------------
1 | setApplicationName("Google Prediction Sample");
33 |
34 | // Set your cached access token. Remember to replace $_SESSION with a
35 | // real database or memcached.
36 | session_start();
37 | if (isset($_SESSION['token'])) {
38 | $client->setAccessToken($_SESSION['token']);
39 | }
40 |
41 | // Load the key in PKCS 12 format (you need to download this from the
42 | // Google API Console when the service account was created.
43 | $key = file_get_contents(KEY_FILE);
44 | $client->setAssertionCredentials(new Google_AssertionCredentials(
45 | SERVICE_ACCOUNT_NAME,
46 | array('https://www.googleapis.com/auth/prediction'),
47 | $key)
48 | );
49 |
50 | $client->setClientId(CLIENT_ID);
51 | $service = new Google_PredictionService($client);
52 |
53 |
54 | // Prediction logic:
55 | $id = 'sample.languageid';
56 | $predictionData = new Google_InputInput();
57 | $predictionData->setCsvInstance(array('Je suis fatigue'));
58 |
59 | $input = new Google_Input();
60 | $input->setInput($predictionData);
61 |
62 | $result = $service->hostedmodels->predict($id, $input);
63 | print 'Prediction Result:
' . print_r($result, true) . '
';
64 |
65 | // We're not done yet. Remember to update the cached access token.
66 | // Remember to replace $_SESSION with a real database or memcached.
67 | if ($client->getAccessToken()) {
68 | $_SESSION['token'] = $client->getAccessToken();
69 | }
--------------------------------------------------------------------------------
/test/general/ApiOAuth2Test.php:
--------------------------------------------------------------------------------
1 | developerKey = "devKey";
31 | $oauth->clientId = "clientId1";
32 | $oauth->clientSecret = "clientSecret1";
33 | $oauth->redirectUri = "http://localhost";
34 | $oauth->approvalPrompt = 'force';
35 | $oauth->accessType = "offline";
36 |
37 | $req = new Google_HttpRequest('http://localhost');
38 | $req = $oauth->sign($req);
39 |
40 | $this->assertEquals('http://localhost?key=devKey', $req->getUrl());
41 |
42 | // test accessToken
43 | $oauth->token = array(
44 | 'access_token' => 'ACCESS_TOKEN',
45 | 'created' => time(),
46 | 'expires_in' => '3600'
47 | );
48 |
49 | $req = $oauth->sign($req);
50 | $auth = $req->getRequestHeader('authorization');
51 | $this->assertEquals('Bearer ACCESS_TOKEN', $auth);
52 | }
53 |
54 | public function testCreateAuthUrl() {
55 | $oauth = new Google_OAuth2();
56 |
57 | $oauth->developerKey = "devKey";
58 | $oauth->clientId = "clientId1";
59 | $oauth->clientSecret = "clientSecret1";
60 | $oauth->redirectUri = "http://localhost";
61 | $oauth->approvalPrompt = 'force';
62 | $oauth->accessType = "offline";
63 |
64 | $authUrl = $oauth->createAuthUrl("http://googleapis.com/scope/foo");
65 | $expected = "https://accounts.google.com/o/oauth2/auth"
66 | . "?response_type=code"
67 | . "&redirect_uri=http%3A%2F%2Flocalhost"
68 | . "&client_id=clientId1"
69 | . "&scope=http%3A%2F%2Fgoogleapis.com%2Fscope%2Ffoo"
70 | . "&access_type=offline"
71 | . "&approval_prompt=force";
72 | $this->assertEquals($expected, $authUrl);
73 | }
74 | }
75 |
76 |
--------------------------------------------------------------------------------
/examples/books/interface.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
17 |
18 |
19 | Books Data API Browser in PHP
20 |
21 |
23 |
45 |
46 |
47 |
48 |
50 |
51 |
Books Data API Browser in PHP
52 |
53 |
54 |
55 |
56 |
Search Books:
57 |
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/examples/youtube/search.php:
--------------------------------------------------------------------------------
1 |
4 |
5 | Search Term:
6 |
7 |
8 | Max Results:
9 |
10 |
11 |
12 | END;
13 |
14 | if ($_GET['q'] && $_GET['maxResults']) {
15 | // Call set_include_path() as needed to point to your client library.
16 | require_once 'google-api-php-client/src/Google_Client.php';
17 | require_once 'google-api-php-client/src/contrib/Google_YouTubeService.php';
18 |
19 | /* Set $DEVELOPER_KEY to the "API key" value from the "Access" tab of the
20 | Google APIs Console
21 | Please ensure that you have enabled the YouTube Data API for your project. */
22 | $DEVELOPER_KEY = 'REPLACE ME';
23 |
24 | $client = new Google_Client();
25 | $client->setDeveloperKey($DEVELOPER_KEY);
26 |
27 | $youtube = new Google_YoutubeService($client);
28 |
29 | try {
30 | $searchResponse = $youtube->search->listSearch('id,snippet', array(
31 | 'q' => $_GET['q'],
32 | 'maxResults' => $_GET['maxResults'],
33 | ));
34 |
35 | $videos = '';
36 | $channels = '';
37 | $playlists = '';
38 |
39 | foreach ($searchResponse['items'] as $searchResult) {
40 | switch ($searchResult['id']['kind']) {
41 | case 'youtube#video':
42 | $videos .= sprintf('%s (%s)', $searchResult['snippet']['title'],
43 | $searchResult['id']['videoId']);
44 | break;
45 | case 'youtube#channel':
46 | $channels .= sprintf('%s (%s)', $searchResult['snippet']['title'],
47 | $searchResult['id']['channelId']);
48 | break;
49 | case 'youtube#playlist':
50 | $playlists .= sprintf('%s (%s)', $searchResult['snippet']['title'],
51 | $searchResult['id']['playlistId']);
52 | break;
53 | }
54 | }
55 |
56 | $htmlBody .= <<Videos
58 |
59 | Channels
60 |
61 | Playlists
62 |
63 | END;
64 | } catch (Google_ServiceException $e) {
65 | $htmlBody .= sprintf('A service error occurred: %s
',
66 | htmlspecialchars($e->getMessage()));
67 | } catch (Google_Exception $e) {
68 | $htmlBody .= sprintf('An client error occurred: %s
',
69 | htmlspecialchars($e->getMessage()));
70 | }
71 | }
72 | ?>
73 |
74 |
75 |
76 |
77 | YouTube Search
78 |
79 |
80 | =$htmlBody?>
81 |
82 |
83 |
--------------------------------------------------------------------------------
/examples/adsensehost/examples/AddAdUnitToPublisher.php:
--------------------------------------------------------------------------------
1 |
29 | */
30 | class AddAdUnitToPublisher extends BaseExample {
31 | public function render() {
32 | $accountId = PUBLISHER_ACCOUNT_ID;
33 | $adClientId = PUBLISHER_AD_CLIENT_ID;
34 |
35 | $adUnit = new Google_AdUnit();
36 | $adUnit->setName(sprintf('Ad Unit #%s', $this->getUniqueName()));
37 |
38 | $contentAdsSettings = new Google_AdUnitContentAdsSettings();
39 | $backupOption = new Google_AdUnitContentAdsSettingsBackupOption();
40 | $backupOption->setType('COLOR');
41 | $backupOption->setColor('ffffff');
42 | $contentAdsSettings->setBackupOption($backupOption);
43 | $contentAdsSettings->setSize('SIZE_200_200');
44 | $contentAdsSettings->setType('TEXT');
45 | $adUnit->setContentAdsSettings($contentAdsSettings);
46 |
47 | $customStyle = new Google_AdStyle();
48 | $colors = new Google_AdStyleColors();
49 | $colors->setBackground('ffffff');
50 | $colors->setBorder('000000');
51 | $colors->setText('000000');
52 | $colors->setTitle('000000');
53 | $colors->setUrl('0000ff');
54 | $customStyle->setColors($colors);
55 | $customStyle->setCorners('SQUARE');
56 | $font = new AdStyleFont();
57 | $font->setFamily('ACCOUNT_DEFAULT_FAMILY');
58 | $font->setSize('ACCOUNT_DEFAULT_SIZE');
59 | $customStyle->setFont($font);
60 | $adUnit->setCustomStyle($customStyle);
61 |
62 | // Retrieve custom channels list, and display it.
63 | $result = $this->adSenseHostService->accounts_adunits
64 | ->insert($accountId, $adClientId, $adUnit);
65 | $mainFormat =
66 | 'Ad unit w/ ID "%s", type "%s", name "%s" and status "%s" was created.';
67 | $content = sprintf($mainFormat, $result['id'],
68 | $result['contentAdsSettings']['type'], $result['name'],
69 | $result['status']);
70 | print $content;
71 | }
72 | }
73 |
74 |
--------------------------------------------------------------------------------