├── README.md ├── files └── example.txt ├── google-api-php-client ├── LICENSE ├── NOTICE ├── README ├── examples │ ├── adexchangebuyer │ │ ├── BaseExample.php │ │ ├── examples │ │ │ ├── GetAllAccounts.php │ │ │ ├── GetCreative.php │ │ │ ├── GetDirectDeals.php │ │ │ ├── SubmitCreative.php │ │ │ └── UpdateAccount.php │ │ ├── htmlHelper.php │ │ ├── index.php │ │ └── style.css │ ├── adsense │ │ ├── AdSenseAuth.php │ │ ├── BaseExample.php │ │ ├── examples │ │ │ ├── GenerateColumnChart.php │ │ │ ├── GenerateGeoChart.php │ │ │ ├── GenerateLineChart.php │ │ │ ├── GeneratePieChart.php │ │ │ ├── GenerateReport.php │ │ │ ├── GenerateReportWithPaging.php │ │ │ ├── GenerateTableChart.php │ │ │ ├── GetAccountTree.php │ │ │ ├── GetAllAccounts.php │ │ │ ├── GetAllAdClients.php │ │ │ ├── GetAllAdClientsForAccount.php │ │ │ ├── GetAllAdUnits.php │ │ │ ├── GetAllAdUnitsForCustomChannel.php │ │ │ ├── GetAllCustomChannels.php │ │ │ ├── GetAllCustomChannelsForAdUnit.php │ │ │ └── GetAllUrlChannels.php │ │ ├── htmlHelper.php │ │ ├── index.php │ │ └── style.css │ ├── adsensehost │ │ ├── AdSenseHostAuth.php │ │ ├── BaseExample.php │ │ ├── examples │ │ │ ├── AddAdUnitToPublisher.php │ │ │ ├── AddCustomChannelToHost.php │ │ │ ├── AddUrlChannelToHost.php │ │ │ ├── DeleteAdUnitOnPublisher.php │ │ │ ├── DeleteCustomChannelOnHost.php │ │ │ ├── DeleteUrlChannelOnHost.php │ │ │ ├── GenerateReportForHost.php │ │ │ ├── GenerateReportForPublisher.php │ │ │ ├── GetAccountDataForExistingPublisher.php │ │ │ ├── GetAllAdClientsForHost.php │ │ │ ├── GetAllAdClientsForPublisher.php │ │ │ ├── GetAllAdUnitsForPublisher.php │ │ │ ├── GetAllCustomChannelsForHost.php │ │ │ ├── GetAllUrlChannelsForHost.php │ │ │ ├── StartAssociationSession.php │ │ │ ├── UpdateAdUnitOnPublisher.php │ │ │ ├── UpdateCustomChannelOnHost.php │ │ │ └── VerifyAssociationSession.php │ │ ├── htmlHelper.php │ │ ├── index.php │ │ └── style.css │ ├── affiliateNetwork │ │ └── index.php │ ├── analytics │ │ ├── demo │ │ │ ├── authHelper.php │ │ │ ├── coreReportingApiReference.php │ │ │ ├── helloAnalyticsApi.php │ │ │ ├── index.php │ │ │ ├── managementApiReference.php │ │ │ └── storage.php │ │ └── simple.php │ ├── apps │ │ └── index.php │ ├── batch.php │ ├── books │ │ ├── books_browser.css │ │ ├── index.php │ │ ├── interface.html │ │ └── simple.php │ ├── calendar │ │ └── simple.php │ ├── contacts │ │ └── simple.php │ ├── customSearch │ │ └── index.php │ ├── latitude │ │ ├── index.php │ │ └── style.css │ ├── moments │ │ └── simple.php │ ├── pagespeed │ │ ├── index.php │ │ └── style.css │ ├── plus │ │ ├── README │ │ ├── index.php │ │ ├── simple.php │ │ └── style.css │ ├── prediction │ │ ├── README │ │ ├── index.php │ │ ├── serviceAccount.php │ │ └── style.css │ ├── shopping │ │ └── simple.php │ ├── siteVerification │ │ └── simple.php │ ├── tasks │ │ ├── css │ │ │ └── style.css │ │ └── index.php │ ├── translate │ │ └── simple.php │ ├── urlshortener │ │ ├── index.php │ │ └── style.css │ ├── userinfo │ │ └── index.php │ └── webfonts │ │ └── simple.php ├── makeRelease.sh ├── src │ ├── Google_Client.php │ ├── auth │ │ ├── Google_AssertionCredentials.php │ │ ├── Google_Auth.php │ │ ├── Google_AuthNone.php │ │ ├── Google_LoginTicket.php │ │ ├── Google_OAuth2.php │ │ ├── Google_P12Signer.php │ │ ├── Google_PemVerifier.php │ │ ├── Google_Signer.php │ │ └── Google_Verifier.php │ ├── cache │ │ ├── Google_ApcCache.php │ │ ├── Google_Cache.php │ │ ├── Google_FileCache.php │ │ └── Google_MemcacheCache.php │ ├── config.php │ ├── contrib │ │ ├── Google_AdExchangeSellerService.php │ │ ├── Google_AdexchangebuyerService.php │ │ ├── Google_AdsenseService.php │ │ ├── Google_AdsensehostService.php │ │ ├── Google_AnalyticsService.php │ │ ├── Google_BigqueryService.php │ │ ├── Google_BloggerService.php │ │ ├── Google_BooksService.php │ │ ├── Google_CalendarService.php │ │ ├── Google_ComputeService.php │ │ ├── Google_CustomsearchService.php │ │ ├── Google_DriveService.php │ │ ├── Google_FreebaseService.php │ │ ├── Google_FusiontablesService.php │ │ ├── Google_GanService.php │ │ ├── Google_LatitudeService.php │ │ ├── Google_LicensingService.php │ │ ├── Google_ModeratorService.php │ │ ├── Google_Oauth2Service.php │ │ ├── Google_OrkutService.php │ │ ├── Google_PagespeedonlineService.php │ │ ├── Google_PlusMomentsService.php │ │ ├── Google_PlusService.php │ │ ├── Google_PredictionService.php │ │ ├── Google_ShoppingService.php │ │ ├── Google_SiteVerificationService.php │ │ ├── Google_StorageService.php │ │ ├── Google_TaskqueueService.php │ │ ├── Google_TasksService.php │ │ ├── Google_TranslateService.php │ │ ├── Google_UrlshortenerService.php │ │ ├── Google_WebfontsService.php │ │ └── Google_YoutubeService.php │ ├── external │ │ └── URITemplateParser.php │ ├── io │ │ ├── Google_CacheParser.php │ │ ├── Google_CurlIO.php │ │ ├── Google_HttpRequest.php │ │ ├── Google_IO.php │ │ ├── Google_REST.php │ │ ├── Google_REST.php~ │ │ └── cacerts.pem │ └── service │ │ ├── Google_BatchRequest.php │ │ ├── Google_MediaFileUpload.php │ │ ├── Google_Model.php │ │ ├── Google_Service.php │ │ ├── Google_ServiceResource.php │ │ └── Google_Utils.php ├── static │ └── Credentials.png └── test │ ├── AllTests.php │ ├── BaseTest.php │ ├── README │ ├── adsense │ └── AdSenseTest.php │ ├── general │ ├── ApiBatchRequestTest.php │ ├── ApiCacheParserTest.php │ ├── ApiClientTest.php │ ├── ApiMediaFileUploadTest.php │ ├── ApiModelTest.php │ ├── ApiOAuth2Test.php │ ├── AuthTest.php │ ├── CacheTest.php │ ├── GeneralTests.php │ ├── IoTest.php │ ├── OAuthHelper.php │ ├── RestTest.php │ ├── ServiceTest.php │ └── testdata │ │ └── test_public_key.pem │ ├── pagespeed │ ├── AllPageSpeedTests.php │ └── PageSpeedTest.php │ ├── phpunit.xml │ ├── plus │ └── PlusTest.php │ ├── tasks │ ├── AllTasksTests.php │ └── TasksTest.php │ └── urlshortener │ ├── AllUrlShortenerTests.php │ └── UrlShortenerTests.php ├── index.php └── index.phtml /README.md: -------------------------------------------------------------------------------- 1 | Google-Drive-PHP-API-Simple-App-Example 2 | ======================================= 3 | 4 | A very simple File Upload to Google Drive app sample powered with PHP. 5 | 6 | This is the source code I have developed to write the article "Subiendo archivos a Google Drive con PHP" available at http://www.eduardocasas.com/blog/05-12-2012/subiendo-archivos-a-google-drive-con-php -------------------------------------------------------------------------------- /files/example.txt: -------------------------------------------------------------------------------- 1 | Hello World! 2 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 ''; 67 | } 68 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/examples/adsense/examples/GenerateReportWithPaging.php: -------------------------------------------------------------------------------- 1 | 33 | */ 34 | 35 | class GenerateReportWithPaging extends BaseExample { 36 | public function render() { 37 | $startDate = $this->getSixMonthsBeforeNow(); 38 | $endDate = $this->getNow(); 39 | $optParams = array( 40 | 'metric' => array( 41 | 'PAGE_VIEWS', 'AD_REQUESTS', 'AD_REQUESTS_COVERAGE', 42 | 'CLICKS', 'AD_REQUESTS_CTR', 'COST_PER_CLICK', 'AD_REQUESTS_RPM', 43 | 'EARNINGS'), 44 | 'dimension' => 'DATE', 45 | 'sort' => 'DATE', 46 | 'filter' => array( 47 | 'AD_CLIENT_ID==' . AD_CLIENT_ID 48 | ) 49 | ); 50 | // Retrieve report in pages and display data as we receive it. 51 | $startIndex = 0; 52 | $rowsToObtain = AD_MAX_PAGE_SIZE; 53 | do { 54 | $optParams['startIndex'] = $startIndex; 55 | $optParams['maxResults'] = $rowsToObtain; 56 | $report = $this->adSenseService->reports 57 | ->generate($startDate, $endDate, $optParams); 58 | 59 | if ($report['totalMatchedRows'] > AD_ROW_LIMIT) { 60 | printPaginationError(); 61 | break; 62 | } else { 63 | if ($startIndex == 0) { 64 | printReportTableHeader($report['headers']); 65 | if ($report['totalMatchedRows'] == 0) { 66 | printNoResultForTable(count($report['headers'])); 67 | break; 68 | } 69 | } 70 | if (isset($report['rows'])) { 71 | printReportTableRows($report['rows']); 72 | $startIndex += count($report['rows']); 73 | } 74 | } 75 | } while ($startIndex < $report['totalMatchedRows']); 76 | printReportTableFooter(); 77 | } 78 | } 79 | 80 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/examples/adsense/examples/GetAllCustomChannels.php: -------------------------------------------------------------------------------- 1 | 28 | */ 29 | class GetAllCustomChannels 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 custom channels list, and display it. 39 | $result = $this->adSenseService->customchannels 40 | ->listCustomchannels($adClientId, $optParams); 41 | $customChannels = $result['items']; 42 | if (isset($customChannels)) { 43 | foreach ($customChannels as $customChannel) { 44 | $content = array(); 45 | $mainFormat = 46 | 'Custom channel with code "%s" and name "%s" was found.'; 47 | $content[] = sprintf($mainFormat, $customChannel['code'], 48 | $customChannel['name']); 49 | if($customChannel['targetingInfo']) { 50 | $targetingInfo = $customChannel['targetingInfo']; 51 | if($targetingInfo['adsAppearOn']) { 52 | $content[] = sprintf('Ads appear on: %s', 53 | $targetingInfo['adsAppearOn']); 54 | } 55 | if($targetingInfo['location']) { 56 | $content[] = sprintf('Location: %s', $targetingInfo['location']); 57 | } 58 | if($targetingInfo['description']) { 59 | $content[] = sprintf('Description: %s', 60 | $targetingInfo['description']); 61 | } 62 | if($targetingInfo['siteLanguage']) { 63 | $content[] = sprintf('Site language: %s', 64 | $targetingInfo['siteLanguage']); 65 | } 66 | } 67 | printListElementForClients($content); 68 | } 69 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken'] 70 | : null; 71 | } else { 72 | printNoResultForList(); 73 | } 74 | } while ($pageToken); 75 | printListFooter(); 76 | } 77 | } 78 | 79 | -------------------------------------------------------------------------------- /google-api-php-client/examples/adsense/examples/GetAllCustomChannelsForAdUnit.php: -------------------------------------------------------------------------------- 1 | 28 | */ 29 | class GetAllCustomChannelsForAdUnit extends BaseExample { 30 | public function render() { 31 | $accountId = ACCOUNT_ID; 32 | $adClientId = AD_CLIENT_ID; 33 | $adUnitId = AD_UNIT_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 custom channels list, and display it. 41 | $result = $this->adSenseService->accounts_adunits_customchannels 42 | ->listAccountsAdunitsCustomchannels( 43 | $accountId, $adClientId, $adUnitId); 44 | $customChannels = $result['items']; 45 | if (isset($customChannels)) { 46 | foreach ($customChannels as $customChannel) { 47 | $content = array(); 48 | $mainFormat = 49 | 'Custom channel with code "%s" and name "%s" was found.'; 50 | $content[] = sprintf($mainFormat, $customChannel['code'], 51 | $customChannel['name']); 52 | if($customChannel['targetingInfo']) { 53 | $targetingInfo = $customChannel['targetingInfo']; 54 | if($targetingInfo['adsAppearOn']) { 55 | $content[] = sprintf('Ads appear on: %s', 56 | $targetingInfo['adsAppearOn']); 57 | } 58 | if($targetingInfo['location']) { 59 | $content[] = sprintf('Location: %s', $targetingInfo['location']); 60 | } 61 | if($targetingInfo['description']) { 62 | $content[] = sprintf('Description: %s', 63 | $targetingInfo['description']); 64 | } 65 | if($targetingInfo['siteLanguage']) { 66 | $content[] = sprintf('Site language: %s', 67 | $targetingInfo['siteLanguage']); 68 | } 69 | } 70 | printListElementForClients($content); 71 | } 72 | $pageToken = isset($result['nextPageToken']) ? $result['nextPageToken'] 73 | : null; 74 | } else { 75 | printNoResultForList(); 76 | } 77 | } while ($pageToken); 78 | printListFooter(); 79 | } 80 | } 81 | 82 | -------------------------------------------------------------------------------- /google-api-php-client/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 (isset($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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/examples/adsensehost/examples/GetAllAdClientsForPublisher.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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 ""; 61 | } else { 62 | print "Logout"; 63 | } -------------------------------------------------------------------------------- /google-api-php-client/examples/analytics/demo/storage.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 ""; 49 | } -------------------------------------------------------------------------------- /google-api-php-client/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 ""; 62 | } 63 | -------------------------------------------------------------------------------- /google-api-php-client/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 } -------------------------------------------------------------------------------- /google-api-php-client/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 |
58 | 63 | 64 | 65 | 66 | 67 | 70 |
71 |
72 |
73 |
74 | 75 | -------------------------------------------------------------------------------- /google-api-php-client/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 | } -------------------------------------------------------------------------------- /google-api-php-client/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 ""; 39 | } -------------------------------------------------------------------------------- /google-api-php-client/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 ""; 64 | } else { 65 | print "Logout"; 66 | } -------------------------------------------------------------------------------- /google-api-php-client/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) . "
"; -------------------------------------------------------------------------------- /google-api-php-client/examples/latitude/index.php: -------------------------------------------------------------------------------- 1 | setClientId('insert_your_oauth2_client_id'); 26 | // $client->setClientSecret('insert_your_oauth2_client_secret'); 27 | // $client->setRedirectUri('insert_your_oauth2_redirect_uri'); 28 | $client->setApplicationName("Latitude_Example_App"); 29 | $service = new Google_LatitudeService($client); 30 | 31 | if (isset($_REQUEST['logout'])) { 32 | unset($_SESSION['access_token']); 33 | } 34 | 35 | if (isset($_GET['code'])) { 36 | $client->authenticate($_GET['code']); 37 | $_SESSION['access_token'] = $client->getAccessToken(); 38 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 39 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); 40 | } 41 | 42 | if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { 43 | $client->setAccessToken($_SESSION['access_token']); 44 | } else { 45 | $authUrl = $client->createAuthUrl(); 46 | } 47 | 48 | if ($client->getAccessToken()) { 49 | // Start to make API requests. 50 | //$location = $service->location->listLocation(); 51 | $currentLocation = $service->currentLocation->get(); 52 | $_SESSION['access_token'] = $client->getAccessToken(); 53 | } 54 | ?> 55 | 56 | 57 | 58 | 59 |

Google Latitude Sample App

60 |
61 | 62 |
63 |
64 |
65 | 66 | 67 | 68 |
69 |
70 |
71 | 72 | 73 | Connect Me!"; 76 | } else { 77 | print "Logout"; 78 | } 79 | ?> 80 |
81 | -------------------------------------------------------------------------------- /google-api-php-client/examples/latitude/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: 350px; 35 | height: auto; 36 | 37 | margin: auto; 38 | padding: 10px; 39 | } 40 | 41 | .currentLocation { 42 | -webkit-box-flex: 1; 43 | -moz-box-flex: 1; 44 | box-flex: 1; 45 | width: 100px; 46 | } 47 | 48 | .location { 49 | -webkit-box-flex: 2; 50 | -moz-box-flex: 2; 51 | box-flex: 2; 52 | width:100%; 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 | } 88 | -------------------------------------------------------------------------------- /google-api-php-client/examples/moments/simple.php: -------------------------------------------------------------------------------- 1 | setApplicationName("Google+ history example"); 11 | $client->setClientId('insert_client_id'); 12 | $client->setClientSecret('insert_client_secret'); 13 | $client->setRedirectUri('insert_redirect_uri'); 14 | $client->setDeveloperKey('insert_developer_key'); 15 | 16 | $moments = new Google_PlusMomentsService($client); 17 | 18 | if (isset($_GET['signout'])) { 19 | unset($_SESSION['token']); 20 | } 21 | 22 | if (isset($_GET['code'])) { 23 | // Validate the state parameter (the CSRF token generated with the 24 | // Google+ sign-in button). 25 | if (strval($_SESSION['state']) !== strval($_GET['state'])) { 26 | die("The session state did not match."); 27 | } 28 | 29 | unset($_SESSION['state']); 30 | 31 | // Receive an OAuth 2.0 authorization code via the GET parameter 'code'. 32 | // Exchange the OAuth 2.0 authorization code for user credentials. 33 | $client->authenticate($_GET['code']); 34 | $_SESSION['token'] = $client->getAccessToken(); 35 | print ''; 36 | exit(0); 37 | } 38 | 39 | // Recall the credentials from the session. In practice, you want to 40 | // look-up the token from a database. 41 | if (isset($_SESSION['token'])) { 42 | $client->setAccessToken($_SESSION['token']); 43 | } 44 | 45 | if ($client->isAccessTokenExpired()) { 46 | 47 | // Generate a unique CSRF token. 48 | $state = sha1(uniqid(mt_rand(), true)); 49 | $_SESSION['state'] = $state; 50 | 51 | // Render the Google+ sign-in button. 52 | print << 54 | 55 | 62 | 63 | 68 | 69 | MARKUP; 70 | 71 | } else { 72 | // Build the moment to write 73 | $target = new Google_ItemScope(); 74 | $target->url = 'https://developers.google.com/+/plugins/snippet/examples/thing'; 75 | 76 | $moment = new Google_Moment(); 77 | $moment->type = "http://schemas.google.com/AddActivity"; 78 | $moment->target = $target; 79 | 80 | // Execute the request 81 | $moments->moments->insert('me', 'vault', $moment); 82 | print '

Created an AddActivity moment

'; 83 | 84 | $_SESSION['token'] = $client->getAccessToken(); 85 | } -------------------------------------------------------------------------------- /google-api-php-client/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 | 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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | } -------------------------------------------------------------------------------- /google-api-php-client/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 -------------------------------------------------------------------------------- /google-api-php-client/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 ""; 61 | } -------------------------------------------------------------------------------- /google-api-php-client/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 | } -------------------------------------------------------------------------------- /google-api-php-client/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 "Sevices" 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 | -------------------------------------------------------------------------------- /google-api-php-client/examples/prediction/index.php: -------------------------------------------------------------------------------- 1 | setApplicationName("Google Prediction API PHP Starter Application"); 26 | // Visit https://code.google.com/apis/console/?api=prediction to generate 27 | // your oauth2_client_id, oauth2_client_secret, and to register your 28 | // oauth2_redirect_uri. 29 | // $client->setClientId('insert_your_oauth2_client_id'); 30 | // $client->setClientSecret('insert_your_oauth2_client_secret'); 31 | // $client->setRedirectUri('insert_your_oauth2_redirect_uri'); 32 | // $client->setDeveloperKey('insert_your_developer_key'); 33 | $client->setScopes(array('https://www.googleapis.com/auth/prediction')); 34 | 35 | $predictionService = new Google_PredictionService($client); 36 | $trainedmodels = $predictionService->trainedmodels; 37 | 38 | if (isset($_REQUEST['logout'])) { 39 | unset($_SESSION['access_token']); 40 | } 41 | 42 | if (isset($_GET['code'])) { 43 | $client->authenticate(); 44 | $_SESSION['access_token'] = $client->getAccessToken(); 45 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 46 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); 47 | } 48 | 49 | if (isset($_SESSION['access_token'])) { 50 | $client->setAccessToken($_SESSION['access_token']); 51 | } 52 | 53 | if ($client->getAccessToken()) { 54 | $status = "Logged In"; 55 | } else { 56 | $status = "Logged Out"; 57 | $authUrl = $client->createAuthUrl(); 58 | } 59 | ?> 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 |

Google Prediction API Sample App (PHP)

69 |
70 | 71 | 72 | 73 | Login"; 76 | $result = ""; 77 | print("
"); 78 | } else { 79 | print ""; 80 | /* prediction logic follows... */ 81 | $id = "languages"; 82 | $predictionText = "Je suis fatigue"; 83 | $predictionData = new Google_InputInput(); 84 | $predictionData->setCsvInstance(array($predictionText)); 85 | $input = new Google_Input(); 86 | $input->setInput($predictionData); 87 | $result = $predictionService->trainedmodels->predict($id, $input); 88 | print("

Prediction Result:

"); 89 | print_r($result); 90 | } 91 | ?> 92 | 93 | 94 | -------------------------------------------------------------------------------- /google-api-php-client/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 | } -------------------------------------------------------------------------------- /google-api-php-client/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 | } -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 ""; 40 | } -------------------------------------------------------------------------------- /google-api-php-client/examples/tasks/css/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 | body { 18 | font-family:'Droid Sans', Arial; 19 | font-size:18px; 20 | background:#EEE; 21 | color:#444; 22 | } 23 | 24 | a { 25 | color:#36b; 26 | } 27 | 28 | p, h1, h3 { 29 | font-weight:normal; 30 | margin:10px 0; 31 | padding:0; 32 | } 33 | 34 | h1 { 35 | font-size:30px; 36 | } 37 | 38 | #bottom { 39 | width:800px; 40 | margin:0 auto; 41 | } 42 | 43 | #top { 44 | padding:2px 10px; 45 | font-size:14px; 46 | color:#fff; 47 | border-bottom:1px solid #000; 48 | } 49 | 50 | #top h1.logo { 51 | margin:6px 0; 52 | padding:0; 53 | cursor:pointer; 54 | font-size:24px; 55 | line-height:20px; 56 | } 57 | 58 | #top h1.logo a { 59 | color:#fff; 60 | text-decoration:none; 61 | } 62 | 63 | #bottom { 64 | padding:6px 0 6px 10px; 65 | font-size:11px; 66 | color:#aaa; 67 | } 68 | 69 | #bottom a { 70 | color:#333; 71 | } 72 | 73 | #top { 74 | color:#000; 75 | border:1px solid #ddd; 76 | border-bottom:1px solid #000; 77 | padding:2px 5px; 78 | } 79 | 80 | #top h1.logo a { 81 | color:#000; 82 | } 83 | 84 | #identity { 85 | display:block; 86 | float:right; 87 | padding:0; 88 | margin:0; 89 | vertical-align:super; 90 | } 91 | 92 | #identity img { 93 | width:28px; 94 | height:28px; 95 | } 96 | 97 | img { 98 | border-style:none; 99 | } 100 | #content { 101 | padding:0; 102 | } 103 | 104 | #main { 105 | padding:1px 10px 1px 10px; 106 | margin:0; 107 | } 108 | 109 | #main h3 { 110 | padding:6px 0 2px 0; 111 | margin:0; 112 | } 113 | 114 | #container { 115 | width:990px; 116 | margin:0 auto; 117 | position:relative; 118 | background:white; 119 | border:1px solid #AAA; 120 | border-top:0; 121 | -webkit-box-shadow:#CCC 4px 0px 10px, #CCC -4px 0px 10px, #AAA 0px 38px 36px -24px; 122 | -moz-box-shadow:#CCC 4px 0px 10px, #CCC -4px 0px 10px, #AAA 0px 38px 36px -24px; 123 | box-shadow:#CCC 4px 0px 10px, #CCC -4px 0px 10px, #AAA 0px 38px 36px -24px; 124 | overflow:hidden; 125 | } 126 | 127 | #image { 128 | background:white; 129 | border:1px solid #2276BB; 130 | display:block; 131 | float:left; 132 | margin:0 10px 10px 0; 133 | overflow:hidden; 134 | } 135 | 136 | #task { 137 | background:white; 138 | border:1px solid #999; 139 | clear:left; 140 | font-size:1.2em; 141 | margin-bottom:5px; 142 | padding:8px; 143 | -moz-border-radius:5px; 144 | -webkit-border-radius:5px; 145 | } 146 | -------------------------------------------------------------------------------- /google-api-php-client/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(); ?> -------------------------------------------------------------------------------- /google-api-php-client/examples/translate/simple.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 | -------------------------------------------------------------------------------- /google-api-php-client/examples/urlshortener/index.php: -------------------------------------------------------------------------------- 1 | setClientId('insert_your_oauth2_client_id'); 26 | //$client->setClientSecret('insert_your_oauth2_client_secret'); 27 | //$client->setRedirectUri('insert_your_oauth2_redirect_uri'); 28 | $service = new Google_UrlshortenerService($client); 29 | 30 | if (isset($_REQUEST['logout'])) { 31 | unset($_SESSION['access_token']); 32 | } 33 | 34 | if (isset($_GET['code'])) { 35 | $client->authenticate(); 36 | $_SESSION['access_token'] = $client->getAccessToken(); 37 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 38 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); 39 | } 40 | 41 | if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { 42 | $client->setAccessToken($_SESSION['access_token']); 43 | } else { 44 | $authUrl = $client->createAuthUrl(); 45 | } 46 | 47 | if ($client->getAccessToken() && isset($_GET['url'])) { 48 | // Start to make API requests. 49 | $url = new Google_Url(); 50 | $url->longUrl = $_GET['url']; 51 | $short = $service->url->insert($url); 52 | $_SESSION['access_token'] = $client->getAccessToken(); 53 | } 54 | ?> 55 | 56 | 57 | 58 | 59 |

Google Url Shortener Sample App

60 |
61 |
62 | 63 | 64 | 65 |
66 | 67 | 68 |
69 | Logout 70 | 71 |
72 | 73 | 74 |
75 |
76 |
77 | 78 |
79 | 80 | -------------------------------------------------------------------------------- /google-api-php-client/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 | } -------------------------------------------------------------------------------- /google-api-php-client/examples/userinfo/index.php: -------------------------------------------------------------------------------- 1 | setApplicationName("Google UserInfo PHP Starter Application"); 23 | // Visit https://code.google.com/apis/console?api=plus to generate your 24 | // oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri. 25 | // $client->setClientId('insert_your_oauth2_client_id'); 26 | // $client->setClientSecret('insert_your_oauth2_client_secret'); 27 | // $client->setRedirectUri('insert_your_redirect_uri'); 28 | // $client->setDeveloperKey('insert_your_developer_key'); 29 | $oauth2 = new Google_Oauth2Service($client); 30 | 31 | if (isset($_GET['code'])) { 32 | $client->authenticate($_GET['code']); 33 | $_SESSION['token'] = $client->getAccessToken(); 34 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 35 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); 36 | return; 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 | $user = $oauth2->userinfo->get(); 50 | 51 | // These fields are currently filtered through the PHP sanitize filters. 52 | // See http://www.php.net/manual/en/filter.filters.sanitize.php 53 | $email = filter_var($user['email'], FILTER_SANITIZE_EMAIL); 54 | $img = filter_var($user['picture'], FILTER_VALIDATE_URL); 55 | $personMarkup = "$email
"; 56 | 57 | // The access token may have been updated lazily. 58 | $_SESSION['token'] = $client->getAccessToken(); 59 | } else { 60 | $authUrl = $client->createAuthUrl(); 61 | } 62 | ?> 63 | 64 | 65 | 66 | 67 |

Google UserInfo Sample App

68 | 69 | 70 | 71 | Connect Me!"; 74 | } else { 75 | print "Logout"; 76 | } 77 | ?> 78 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/makeRelease.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | VERSION=0.6.0 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 | cd .. 18 | tar c google-api-php-client | gzip > $RELFILE 19 | rm -rf $TMPDIR 20 | -------------------------------------------------------------------------------- /google-api-php-client/src/auth/Google_AssertionCredentials.php: -------------------------------------------------------------------------------- 1 | 22 | */ 23 | class Google_AssertionCredentials { 24 | const MAX_TOKEN_LIFETIME_SECS = 3600; 25 | 26 | public $serviceAccountName; 27 | public $scopes; 28 | public $privateKey; 29 | public $privateKeyPassword; 30 | public $assertionType; 31 | public $prn; 32 | 33 | /** 34 | * @param $serviceAccountName 35 | * @param $scopes array List of scopes 36 | * @param $privateKey 37 | * @param string $privateKeyPassword 38 | * @param string $assertionType 39 | * @param bool|string $prn The email address of the user for which the 40 | * application is requesting delegated access. 41 | */ 42 | public function __construct( 43 | $serviceAccountName, 44 | $scopes, 45 | $privateKey, 46 | $privateKeyPassword = 'notasecret', 47 | $assertionType = 'http://oauth.net/grant_type/jwt/1.0/bearer', 48 | $prn = false) { 49 | $this->serviceAccountName = $serviceAccountName; 50 | $this->scopes = is_string($scopes) ? $scopes : implode(' ', $scopes); 51 | $this->privateKey = $privateKey; 52 | $this->privateKeyPassword = $privateKeyPassword; 53 | $this->assertionType = $assertionType; 54 | $this->prn = $prn; 55 | } 56 | 57 | public function generateAssertion() { 58 | $now = time(); 59 | 60 | $jwtParams = array( 61 | 'aud' => Google_OAuth2::OAUTH2_TOKEN_URI, 62 | 'scope' => $this->scopes, 63 | 'iat' => $now, 64 | 'exp' => $now + self::MAX_TOKEN_LIFETIME_SECS, 65 | 'iss' => $this->serviceAccountName, 66 | ); 67 | 68 | if ($this->prn !== false) { 69 | $jwtParams['prn'] = $this->prn; 70 | } 71 | 72 | return $this->makeSignedJwt($jwtParams); 73 | } 74 | 75 | /** 76 | * Creates a signed JWT. 77 | * @param array $payload 78 | * @return string The signed JWT. 79 | */ 80 | private function makeSignedJwt($payload) { 81 | $header = array('typ' => 'JWT', 'alg' => 'RS256'); 82 | 83 | $segments = array( 84 | Google_Utils::urlSafeB64Encode(json_encode($header)), 85 | Google_Utils::urlSafeB64Encode(json_encode($payload)) 86 | ); 87 | 88 | $signingInput = implode('.', $segments); 89 | $signer = new Google_P12Signer($this->privateKey, $this->privateKeyPassword); 90 | $signature = $signer->sign($signingInput); 91 | $segments[] = Google_Utils::urlSafeB64Encode($signature); 92 | 93 | return implode(".", $segments); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/src/cache/Google_ApcCache.php: -------------------------------------------------------------------------------- 1 | 25 | */ 26 | class googleApcCache extends Google_Cache { 27 | 28 | public function __construct() { 29 | if (! function_exists('apc_add')) { 30 | throw new Google_CacheException("Apc functions not available"); 31 | } 32 | } 33 | 34 | private function isLocked($key) { 35 | if ((@apc_fetch($key . '.lock')) === false) { 36 | return false; 37 | } 38 | return true; 39 | } 40 | 41 | private function createLock($key) { 42 | // the interesting thing is that this could fail if the lock was created in the meantime.. 43 | // but we'll ignore that out of convenience 44 | @apc_add($key . '.lock', '', 5); 45 | } 46 | 47 | private function removeLock($key) { 48 | // suppress all warnings, if some other process removed it that's ok too 49 | @apc_delete($key . '.lock'); 50 | } 51 | 52 | private function waitForLock($key) { 53 | // 20 x 250 = 5 seconds 54 | $tries = 20; 55 | $cnt = 0; 56 | do { 57 | // 250 ms is a long time to sleep, but it does stop the server from burning all resources on polling locks.. 58 | usleep(250); 59 | $cnt ++; 60 | } while ($cnt <= $tries && $this->isLocked($key)); 61 | if ($this->isLocked($key)) { 62 | // 5 seconds passed, assume the owning process died off and remove it 63 | $this->removeLock($key); 64 | } 65 | } 66 | 67 | /** 68 | * @inheritDoc 69 | */ 70 | public function get($key, $expiration = false) { 71 | 72 | if (($ret = @apc_fetch($key)) === false) { 73 | return false; 74 | } 75 | if (!$expiration || (time() - $ret['time'] > $expiration)) { 76 | $this->delete($key); 77 | return false; 78 | } 79 | return unserialize($ret['data']); 80 | } 81 | 82 | /** 83 | * @inheritDoc 84 | */ 85 | public function set($key, $value) { 86 | if (@apc_store($key, array('time' => time(), 'data' => serialize($value))) == false) { 87 | throw new Google_CacheException("Couldn't store data"); 88 | } 89 | } 90 | 91 | /** 92 | * @inheritDoc 93 | * @param String $key 94 | */ 95 | public function delete($key) { 96 | @apc_delete($key); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/src/io/Google_IO.php: -------------------------------------------------------------------------------- 1 | 26 | */ 27 | interface Google_IO { 28 | /** 29 | * An utility function that first calls $this->auth->sign($request) and then executes makeRequest() 30 | * on that signed request. Used for when a request should be authenticated 31 | * @param Google_HttpRequest $request 32 | * @return Google_HttpRequest $request 33 | */ 34 | public function authenticatedRequest(Google_HttpRequest $request); 35 | 36 | /** 37 | * Executes a apIHttpRequest and returns the resulting populated httpRequest 38 | * @param Google_HttpRequest $request 39 | * @return Google_HttpRequest $request 40 | */ 41 | public function makeRequest(Google_HttpRequest $request); 42 | 43 | /** 44 | * Set options that update the transport implementation's behavior. 45 | * @param $options 46 | */ 47 | public function setOptions($options); 48 | 49 | } 50 | -------------------------------------------------------------------------------- /google-api-php-client/src/service/Google_Service.php: -------------------------------------------------------------------------------- 1 | setName('All Google API PHP Client tests'); 37 | $suite->addTestSuite(AllTasksTests::suite()); 38 | $suite->addTestSuite(AllPageSpeedTests::suite()); 39 | $suite->addTestSuite(AllUrlShortenerTests::suite()); 40 | $suite->addTestSuite(AllPlusTests::suite()); 41 | //$suite->addTestSuite(AdsenseTests::suite()); 42 | 43 | $suite->addTestSuite(GeneralTests::suite()); 44 | return $suite; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /google-api-php-client/test/BaseTest.php: -------------------------------------------------------------------------------- 1 | getAccessToken()) { 32 | BaseTest::$client->setAccessToken($apiConfig['oauth_test_token']); 33 | } 34 | } 35 | } 36 | 37 | public function __destruct() { 38 | global $apiConfig; 39 | $apiConfig['oauth_test_token'] = self::$client->getAccessToken(); 40 | } 41 | } -------------------------------------------------------------------------------- /google-api-php-client/test/README: -------------------------------------------------------------------------------- 1 | These tests depend on PHPUnit, see 2 | http://www.phpunit.de/manual/current/en/installation.html for more instructions 3 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/test/general/ApiModelTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(true); 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | } -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/test/pagespeed/AllPageSpeedTests.php: -------------------------------------------------------------------------------- 1 | setName('Google PageSpeed API tests'); 27 | $suite->addTestSuite('PageSpeedTest'); 28 | return $suite; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/test/tasks/AllTasksTests.php: -------------------------------------------------------------------------------- 1 | setName('Google Tasks API tests'); 27 | $suite->addTestSuite('TasksTest'); 28 | return $suite; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /google-api-php-client/test/urlshortener/AllUrlShortenerTests.php: -------------------------------------------------------------------------------- 1 | setName('Google UrlShortener API tests'); 27 | $suite->addTestSuite('UrlShortenerTests'); 28 | return $suite; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /google-api-php-client/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 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | setClientId('Place your ClientId Here'); 10 | $client->setClientSecret('Place your ClientSecret here'); 11 | $client->setRedirectUri($url); 12 | $client->setScopes(array('https://www.googleapis.com/auth/drive')); 13 | if (isset($_GET['code'])) { 14 | $_SESSION['accessToken'] = $client->authenticate($_GET['code']); 15 | header('location:'.$url);exit; 16 | } elseif (!isset($_SESSION['accessToken'])) { 17 | $client->authenticate(); 18 | } 19 | $files= array(); 20 | $dir = dir('files'); 21 | while ($file = $dir->read()) { 22 | if ($file != '.' && $file != '..') { 23 | $files[] = $file; 24 | } 25 | } 26 | $dir->close(); 27 | if (!empty($_POST)) { 28 | $client->setAccessToken($_SESSION['accessToken']); 29 | $service = new Google_DriveService($client); 30 | $finfo = finfo_open(FILEINFO_MIME_TYPE); 31 | $file = new Google_DriveFile(); 32 | foreach ($files as $file_name) { 33 | $file_path = 'files/'.$file_name; 34 | $mime_type = finfo_file($finfo, $file_path); 35 | $file->setTitle($file_name); 36 | $file->setDescription('This is a '.$mime_type.' document'); 37 | $file->setMimeType($mime_type); 38 | $service->files->insert( 39 | $file, 40 | array( 41 | 'data' => file_get_contents($file_path), 42 | 'mimeType' => $mime_type 43 | ) 44 | ); 45 | } 46 | finfo_close($finfo); 47 | header('location:'.$url);exit; 48 | } 49 | include 'index.phtml'; 50 | -------------------------------------------------------------------------------- /index.phtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Google Drive Example App 6 | 7 | 8 |
    9 | 10 |
  • 11 | 12 |
13 |
14 | 15 |
16 | 17 | 18 | --------------------------------------------------------------------------------