├── .gitattributes ├── README.md ├── google-api-php-client ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── autoload.php ├── composer.json ├── examples │ ├── appengineauth.php │ ├── batch.php │ ├── fileupload.php │ ├── idtoken.php │ ├── index.php │ ├── multi-api.php │ ├── service-account.php │ ├── simple-query.php │ ├── simplefileupload.php │ ├── styles │ │ └── style.css │ ├── templates │ │ └── base.php │ └── user-example.php ├── phpunit.xml.dist ├── src │ └── Google │ │ ├── Auth │ │ ├── Abstract.php │ │ ├── AppIdentity.php │ │ ├── AssertionCredentials.php │ │ ├── Exception.php │ │ ├── LoginTicket.php │ │ ├── OAuth2.php │ │ └── Simple.php │ │ ├── Cache │ │ ├── Abstract.php │ │ ├── Apc.php │ │ ├── Exception.php │ │ ├── File.php │ │ ├── Memcache.php │ │ └── Null.php │ │ ├── Client.php │ │ ├── Collection.php │ │ ├── Config.php │ │ ├── Exception.php │ │ ├── Http │ │ ├── Batch.php │ │ ├── CacheParser.php │ │ ├── MediaFileUpload.php │ │ ├── REST.php │ │ └── Request.php │ │ ├── IO │ │ ├── Abstract.php │ │ ├── Curl.php │ │ ├── Exception.php │ │ ├── Stream.php │ │ └── cacerts.pem │ │ ├── Logger │ │ ├── Abstract.php │ │ ├── Exception.php │ │ ├── File.php │ │ ├── Null.php │ │ └── Psr.php │ │ ├── Model.php │ │ ├── Service.php │ │ ├── Service │ │ ├── AdExchangeBuyer.php │ │ ├── AdExchangeSeller.php │ │ ├── AdSense.php │ │ ├── AdSenseHost.php │ │ ├── Admin.php │ │ ├── Analytics.php │ │ ├── AndroidPublisher.php │ │ ├── AppState.php │ │ ├── Appsactivity.php │ │ ├── Audit.php │ │ ├── Autoscaler.php │ │ ├── Bigquery.php │ │ ├── Blogger.php │ │ ├── Books.php │ │ ├── Calendar.php │ │ ├── CivicInfo.php │ │ ├── CloudMonitoring.php │ │ ├── Cloudlatencytest.php │ │ ├── Compute.php │ │ ├── Container.php │ │ ├── Coordinate.php │ │ ├── Customsearch.php │ │ ├── Dataflow.php │ │ ├── Datastore.php │ │ ├── Deploymentmanager.php │ │ ├── Dfareporting.php │ │ ├── Directory.php │ │ ├── Dns.php │ │ ├── DoubleClickBidManager.php │ │ ├── Doubleclicksearch.php │ │ ├── Drive.php │ │ ├── Exception.php │ │ ├── Fitness.php │ │ ├── Freebase.php │ │ ├── Fusiontables.php │ │ ├── Games.php │ │ ├── GamesConfiguration.php │ │ ├── GamesManagement.php │ │ ├── Genomics.php │ │ ├── Gmail.php │ │ ├── GroupsMigration.php │ │ ├── Groupssettings.php │ │ ├── IdentityToolkit.php │ │ ├── Licensing.php │ │ ├── Manager.php │ │ ├── MapsEngine.php │ │ ├── Mirror.php │ │ ├── Oauth2.php │ │ ├── Pagespeedonline.php │ │ ├── Plus.php │ │ ├── PlusDomains.php │ │ ├── Prediction.php │ │ ├── Pubsub.php │ │ ├── QPXExpress.php │ │ ├── Replicapool.php │ │ ├── Replicapoolupdater.php │ │ ├── Reports.php │ │ ├── Reseller.php │ │ ├── Resource.php │ │ ├── Resourceviews.php │ │ ├── SQLAdmin.php │ │ ├── ShoppingContent.php │ │ ├── SiteVerification.php │ │ ├── Spectrum.php │ │ ├── Storage.php │ │ ├── TagManager.php │ │ ├── Taskqueue.php │ │ ├── Tasks.php │ │ ├── Translate.php │ │ ├── Urlshortener.php │ │ ├── Webfonts.php │ │ ├── Webmasters.php │ │ ├── YouTube.php │ │ └── YouTubeAnalytics.php │ │ ├── Signer │ │ ├── Abstract.php │ │ └── P12.php │ │ ├── Task │ │ ├── Exception.php │ │ ├── Retryable.php │ │ └── Runner.php │ │ ├── Utils.php │ │ ├── Utils │ │ └── URITemplate.php │ │ └── Verifier │ │ ├── Abstract.php │ │ └── Pem.php ├── style │ └── ruleset.xml └── tests │ ├── BaseTest.php │ ├── OAuthHelper.php │ ├── README │ ├── adsense │ └── AdSenseTest.php │ ├── bootstrap.php │ ├── general │ ├── ApiBatchRequestTest.php │ ├── ApiCacheParserTest.php │ ├── ApiClientTest.php │ ├── ApiMediaFileUploadTest.php │ ├── ApiModelTest.php │ ├── ApiOAuth2Test.php │ ├── AuthTest.php │ ├── CacheTest.php │ ├── IoTest.php │ ├── LoggerTest.php │ ├── RequestTest.php │ ├── RestTest.php │ ├── ServiceTest.php │ ├── TaskTest.php │ ├── URITemplateTest.php │ └── testdata │ │ ├── cacert.json │ │ ├── cacert.pem │ │ ├── cert.p12 │ │ ├── privkey.pem │ │ ├── test.ini │ │ └── test_public_key.pem │ ├── pagespeed │ └── PageSpeedTest.php │ ├── plus │ └── PlusTest.php │ ├── tasks │ └── TasksTest.php │ ├── urlshortener │ └── UrlShortenerTests.php │ └── youtube │ └── YouTubeTest.php ├── index.php └── index_files └── formoid1 ├── .htaccess ├── JSON.php ├── form.formoid ├── form.php ├── formoid-solid-red.css ├── formoid-solid-red.js ├── formoid.eot ├── formoid.svg ├── formoid.ttf ├── formoid.woff ├── handler.php ├── helpers.php ├── icons.eot ├── icons.svg ├── icons.ttf ├── icons.woff ├── jquery.min.js └── recaptchalib.php /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **edit: this has been patched. took ~5 years** 2 | 3 | **how to install and use** 4 | 5 | 1. use google developers console to generate api credentials *after enabling drive api* on a new project 6 | 2. edit index.php and insert your clientid, clientsecret and redirecturi starting at line 26 7 | 3. your redirecturi value must be the url that points to index.php 8 | 4. navigate to index.php after hosting it on a local or remote webserver 9 | 10 | ![lulz](https://i.imgur.com/nBBQdf3.png) 11 | 12 | **full name information leak in google drive** 13 | 14 | in 2015 i discovered and reported this leak found in both mapsengine and drive. mapsengine was patched, but it was evidently a feature in drive. many email accounts across several providers whose names aren't visible on g+ or in account recovery procedures become retrievable. this issue was disclosed to google back in 2015. 15 | 16 | **fyi** 17 | 18 | this reveals *way* more full names than account recovery procedures, the "to" field in new emails, etc. and as such [seclists.org commentators](https://seclists.org/fulldisclosure/2015/Jan/95) were and still are [dead wrong](https://youtu.be/gwpFaU7FwtQ?t=117) ¯\\_(ツ)_/¯ 19 | 20 | ![lulz](https://i.imgur.com/RqXaPti.png) 21 | 22 | lulz full disclosure 23 | -------------------------------------------------------------------------------- /google-api-php-client/.gitignore: -------------------------------------------------------------------------------- 1 | phpunit.xml 2 | composer.lock 3 | vendor 4 | examples/testfile-small.txt 5 | examples/testfile.txt 6 | -------------------------------------------------------------------------------- /google-api-php-client/.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | services: 4 | - memcached 5 | 6 | env: 7 | global: 8 | - MEMCACHE_HOST=127.0.0.1 9 | - MEMCACHE_PORT=11211 10 | 11 | sudo: false 12 | 13 | php: 14 | # Can't test against 5.2; openssl is not available: 15 | # http://docs.travis-ci.com/user/languages/php/#PHP-installation 16 | - 5.3 17 | - 5.4 18 | - 5.5 19 | - 5.6 20 | - hhvm 21 | 22 | before_script: 23 | - composer install 24 | - sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then echo "extension=memcache.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;' 25 | - sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then echo "extension=memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;' 26 | - phpenv version-name | grep ^5.[34] && echo "extension=apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true 27 | - phpenv version-name | grep ^5.[34] && echo "apc.enable_cli=1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; true 28 | 29 | script: 30 | - vendor/bin/phpunit 31 | -------------------------------------------------------------------------------- /google-api-php-client/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to become a contributor and submit your own code 2 | 3 | ## Contributor License Agreements 4 | 5 | We'd love to accept your code patches! However, before we can take them, we have to jump a couple of legal hurdles. 6 | 7 | Please fill out either the individual or corporate Contributor License Agreement (CLA). 8 | 9 | * If you are an individual writing original source code and you're sure you own the intellectual property, then you'll need to sign an [individual CLA](http://code.google.com/legal/individual-cla-v1.0.html). 10 | * If you work for a company that wants to allow you to contribute your work to this client library, then you'll need to sign a[corporate CLA](http://code.google.com/legal/corporate-cla-v1.0.html). 11 | 12 | Follow either of the two links above to access the appropriate CLA and instructions for how to sign and return it. Once we receive it, we'll add you to the official list of contributors and be able to accept your patches. 13 | 14 | ## Submitting Patches 15 | 16 | 1. Fork the PHP client library on GitHub 17 | 1. Decide which code you want to submit. A submission should be a set of changes that addresses one issue in the issue tracker. Please file one change per issue, and address one issue per change. If you want to make a change that doesn't have a corresponding issue in the issue tracker, please file a new ticket! 18 | 1. Ensure that your code adheres to standard PHP conventions, as used in the rest of the library. 19 | 1. Ensure that there are unit tests for your code. 20 | 1. Sign a Contributor License Agreement (see above). 21 | 1. Submit a pull request with your patch on Github. 22 | 23 | -------------------------------------------------------------------------------- /google-api-php-client/README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/google/google-api-php-client.svg)](https://travis-ci.org/google/google-api-php-client) 2 | 3 | # Google APIs Client Library for PHP # 4 | 5 | ## Description ## 6 | The Google API Client Library enables you to work with Google APIs such as Google+, Drive, or YouTube on your server. 7 | 8 | ## Beta ## 9 | This library is in Beta. We're comfortable enough with the stability and features of the library that we want you to build real production applications on it. We will make an effort to support the public and protected surface of the library and maintain backwards compatibility in the future. While we are still in Beta, we reserve the right to make incompatible changes. If we do remove some functionality (typically because better functionality exists or if the feature proved infeasible), our intention is to deprecate and provide ample time for developers to update their code. 10 | 11 | ## Requirements ## 12 | * [PHP 5.2.1 or higher](http://www.php.net/) 13 | * [PHP JSON extension](http://php.net/manual/en/book.json.php) 14 | 15 | *Note*: some features (service accounts and id token verification) require PHP 5.3.0 and above due to cryptographic algorithm requirements. 16 | 17 | ## Developer Documentation ## 18 | http://developers.google.com/api-client-library/php 19 | 20 | ## Installation ## 21 | 22 | For the latest installation and setup instructions, see [the documentation](https://developers.google.com/api-client-library/php/start/installation). 23 | 24 | ## Basic Example ## 25 | See the examples/ directory for examples of the key client features. 26 | ```PHP 27 | setApplicationName("Client_Library_Examples"); 33 | $client->setDeveloperKey("YOUR_APP_KEY"); 34 | 35 | $service = new Google_Service_Books($client); 36 | $optParams = array('filter' => 'free-ebooks'); 37 | $results = $service->volumes->listVolumes('Henry David Thoreau', $optParams); 38 | 39 | foreach ($results as $item) { 40 | echo $item['volumeInfo']['title'], "
\n"; 41 | } 42 | 43 | ``` 44 | 45 | ## Frequently Asked Questions ## 46 | 47 | ### What do I do if something isn't working? ### 48 | 49 | For support with the library the best place to ask is via the google-api-php-client tag on StackOverflow: http://stackoverflow.com/questions/tagged/google-api-php-client 50 | 51 | If there is a specific bug with the library, please file a issue in the Github issues tracker, including a (minimal) example of the failing code and any specific errors retrieved. Feature requests can also be filed, as long as they are core library requests, and not-API specific: for those, refer to the documentation for the individual APIs for the best place to file requests. Please try to provide a clear statement of the problem that the feature would address. 52 | 53 | ### How do I contribute? ### 54 | 55 | We accept contributions via Github Pull Requests, but all contributors need to be covered by the standard Google Contributor License Agreement. You can find links, and more instructions, in the documentation: https://developers.google.com/api-client-library/php/contribute 56 | 57 | ### Why do you still support 5.2? ### 58 | 59 | When we started working on the 1.0.0 branch we knew there were several fundamental issues to fix with the 0.6 releases of the library. At that time we looked at the usage of the library, and other related projects, and determined that there was still a large and active base of PHP 5.2 installs. You can see this in statistics such as the PHP versions chart in the WordPress stats: http://wordpress.org/about/stats/. We will keep looking at the types of usage we see, and try to take advantage of newer PHP features where possible. 60 | 61 | ### Why does Google_..._Service have weird names? ### 62 | 63 | The _Service classes are generally automatically generated from the API discovery documents: https://developers.google.com/discovery/. Sometimes new features are added to APIs with unusual names, which can cause some unexpected or non-standard style naming in the PHP classes. 64 | 65 | ### How do I deal with non-JSON response types? ### 66 | 67 | Some services return XML or similar by default, rather than JSON, which is what the library supports. You can request a JSON response by adding an 'alt' argument to optional params that is normally the last argument to a method call: 68 | 69 | ``` 70 | $opt_params = array( 71 | 'alt' => "json" 72 | ); 73 | ``` 74 | 75 | ## Code Quality ## 76 | 77 | Copy the ruleset.xml in style/ into a new directory named GAPI/ in your 78 | /usr/share/php/PHP/CodeSniffer/Standards (or appropriate equivalent directory), 79 | and run code sniffs with: 80 | 81 | phpcs --standard=GAPI src/ 82 | -------------------------------------------------------------------------------- /google-api-php-client/autoload.php: -------------------------------------------------------------------------------- 1 | 3) { 24 | // Maximum class file path depth in this project is 3. 25 | $classPath = array_slice($classPath, 0, 3); 26 | } 27 | $filePath = dirname(__FILE__) . '/src/' . implode('/', $classPath) . '.php'; 28 | if (file_exists($filePath)) { 29 | require_once($filePath); 30 | } 31 | } 32 | 33 | spl_autoload_register('google_api_php_client_autoload'); 34 | -------------------------------------------------------------------------------- /google-api-php-client/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "google/apiclient", 3 | "type": "library", 4 | "description": "Client library for Google APIs", 5 | "keywords": ["google"], 6 | "homepage": "http://developers.google.com/api-client-library/php", 7 | "license": "Apache-2.0", 8 | "require": { 9 | "php": ">=5.2.1" 10 | }, 11 | "require-dev": { 12 | "phpunit/phpunit": "3.7.*" 13 | }, 14 | "autoload": { 15 | "classmap": [ 16 | "src/" 17 | ] 18 | }, 19 | "extra": { 20 | "branch-alias": { 21 | "dev-master": "1.1.x-dev" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /google-api-php-client/examples/appengineauth.php: -------------------------------------------------------------------------------- 1 | setApplicationName("Client_Library_Examples"); 30 | 31 | $auth = new Google_Auth_AppIdentity($client); 32 | $token = $auth->authenticateForScope(Google_Service_Storage::DEVSTORAGE_READ_ONLY); 33 | if (!$token) { 34 | die("Could not authenticate to AppIdentity service"); 35 | } 36 | $client->setAuth($auth); 37 | 38 | $service = new Google_Service_Storage($client); 39 | $results = $service->buckets->listBuckets(str_replace("s~", "", $_SERVER['APPLICATION_ID'])); 40 | 41 | echo "

Results Of Call:

"; 42 | echo "
";
43 | var_dump($results);
44 | echo "
"; 45 | 46 | echo pageFooter(__FILE__); 47 | -------------------------------------------------------------------------------- /google-api-php-client/examples/batch.php: -------------------------------------------------------------------------------- 1 | setApplicationName("Client_Library_Examples"); 35 | $apiKey = ""; // Change to your API key. 36 | // Warn if the API key isn't changed! 37 | if ($apiKey == '') { 38 | echo missingApiKeyWarning(); 39 | } else { 40 | $client->setDeveloperKey($apiKey); 41 | 42 | $service = new Google_Service_Books($client); 43 | 44 | /************************************************ 45 | To actually make the batch call we need to 46 | enable batching on the client - this will apply 47 | globally until we set it to false. This causes 48 | call to the service methods to return the query 49 | rather than immediately executing. 50 | ************************************************/ 51 | $client->setUseBatch(true); 52 | 53 | /************************************************ 54 | We then create a batch, and add each query we 55 | want to execute with keys of our choice - these 56 | keys will be reflected in the returned array. 57 | ************************************************/ 58 | $batch = new Google_Http_Batch($client); 59 | $optParams = array('filter' => 'free-ebooks'); 60 | $req1 = $service->volumes->listVolumes('Henry David Thoreau', $optParams); 61 | $batch->add($req1, "thoreau"); 62 | $req2 = $service->volumes->listVolumes('George Bernard Shaw', $optParams); 63 | $batch->add($req2, "shaw"); 64 | 65 | /************************************************ 66 | Executing the batch will send all requests off 67 | at once. 68 | ************************************************/ 69 | $results = $batch->execute(); 70 | 71 | echo "

Results Of Call 1:

"; 72 | foreach ($results['response-thoreau'] as $item) { 73 | echo $item['volumeInfo']['title'], "
\n"; 74 | } 75 | echo "

Results Of Call 2:

"; 76 | foreach ($results['response-shaw'] as $item) { 77 | echo $item['volumeInfo']['title'], "
\n"; 78 | } 79 | } 80 | 81 | echo pageFooter(__FILE__); 82 | -------------------------------------------------------------------------------- /google-api-php-client/examples/fileupload.php: -------------------------------------------------------------------------------- 1 | '; 39 | $client_secret = ''; 40 | $redirect_uri = ''; 41 | 42 | $client = new Google_Client(); 43 | $client->setClientId($client_id); 44 | $client->setClientSecret($client_secret); 45 | $client->setRedirectUri($redirect_uri); 46 | $client->addScope("https://www.googleapis.com/auth/drive"); 47 | $service = new Google_Service_Drive($client); 48 | 49 | if (isset($_REQUEST['logout'])) { 50 | unset($_SESSION['upload_token ']); 51 | } 52 | 53 | if (isset($_GET['code'])) { 54 | $client->authenticate($_GET['code']); 55 | $_SESSION['upload_token'] = $client->getAccessToken(); 56 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 57 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); 58 | } 59 | 60 | if (isset($_SESSION['upload_token']) && $_SESSION['upload_token']) { 61 | $client->setAccessToken($_SESSION['upload_token']); 62 | if ($client->isAccessTokenExpired()) { 63 | unset($_SESSION['upload_token']); 64 | } 65 | } else { 66 | $authUrl = $client->createAuthUrl(); 67 | } 68 | 69 | /************************************************ 70 | If we're signed in then lets try to upload our 71 | file. 72 | ************************************************/ 73 | if ($client->getAccessToken()) { 74 | $file = new Google_Service_Drive_DriveFile(); 75 | $file->title = "Big File"; 76 | $chunkSizeBytes = 1 * 1024 * 1024; 77 | 78 | // Call the API with the media upload, defer so it doesn't immediately return. 79 | $client->setDefer(true); 80 | $request = $service->files->insert($file); 81 | 82 | // Create a media file upload to represent our upload process. 83 | $media = new Google_Http_MediaFileUpload( 84 | $client, 85 | $request, 86 | 'text/plain', 87 | null, 88 | true, 89 | $chunkSizeBytes 90 | ); 91 | $media->setFileSize(filesize(TESTFILE)); 92 | 93 | // Upload the various chunks. $status will be false until the process is 94 | // complete. 95 | $status = false; 96 | $handle = fopen(TESTFILE, "rb"); 97 | while (!$status && !feof($handle)) { 98 | $chunk = fread($handle, $chunkSizeBytes); 99 | $status = $media->nextChunk($chunk); 100 | } 101 | 102 | // The final value of $status will be the data from the API for the object 103 | // that has been uploaded. 104 | $result = false; 105 | if ($status != false) { 106 | $result = $status; 107 | } 108 | 109 | fclose($handle); 110 | } 111 | echo pageHeader("File Upload - Uploading a large file"); 112 | if ( 113 | $client_id == '' 114 | || $client_secret == '' 115 | || $redirect_uri == '') { 116 | echo missingClientSecretsWarning(); 117 | } 118 | ?> 119 |
120 |
121 | Connect Me!"; 124 | } 125 | ?> 126 |
127 | 128 |
129 | 134 |
135 |
136 | '; 28 | $client_secret = ''; 29 | $redirect_uri = ''; 30 | 31 | $client = new Google_Client(); 32 | $client->setClientId($client_id); 33 | $client->setClientSecret($client_secret); 34 | $client->setRedirectUri($redirect_uri); 35 | $client->setScopes('email'); 36 | 37 | /************************************************ 38 | If we're logging out we just need to clear our 39 | local access token in this case 40 | ************************************************/ 41 | if (isset($_REQUEST['logout'])) { 42 | unset($_SESSION['access_token']); 43 | } 44 | 45 | /************************************************ 46 | If we have a code back from the OAuth 2.0 flow, 47 | we need to exchange that with the authenticate() 48 | function. We store the resultant access token 49 | bundle in the session, and redirect to ourself. 50 | ************************************************/ 51 | if (isset($_GET['code'])) { 52 | $client->authenticate($_GET['code']); 53 | $_SESSION['access_token'] = $client->getAccessToken(); 54 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 55 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); 56 | } 57 | 58 | /************************************************ 59 | If we have an access token, we can make 60 | requests, else we generate an authentication URL. 61 | ************************************************/ 62 | if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { 63 | $client->setAccessToken($_SESSION['access_token']); 64 | } else { 65 | $authUrl = $client->createAuthUrl(); 66 | } 67 | 68 | /************************************************ 69 | If we're signed in we can go ahead and retrieve 70 | the ID token, which is part of the bundle of 71 | data that is exchange in the authenticate step 72 | - we only need to do a network call if we have 73 | to retrieve the Google certificate to verify it, 74 | and that can be cached. 75 | ************************************************/ 76 | if ($client->getAccessToken()) { 77 | $_SESSION['access_token'] = $client->getAccessToken(); 78 | $token_data = $client->verifyIdToken()->getAttributes(); 79 | } 80 | 81 | echo pageHeader("User Query - Retrieving An Id Token"); 82 | if ( 83 | $client_id == '' 84 | || $client_secret == '' 85 | || $redirect_uri == '') { 86 | echo missingClientSecretsWarning(); 87 | } 88 | ?> 89 |
90 |
91 | Connect Me!"; 94 | } else { 95 | echo "Logout"; 96 | } 97 | ?> 98 |
99 | 100 |
101 | 106 |
107 |
108 | 9 | 19 | '; 28 | $client_secret = ''; 29 | $redirect_uri = ''; 30 | 31 | /************************************************ 32 | Make an API request on behalf of a user. In 33 | this case we need to have a valid OAuth 2.0 34 | token for the user, so we need to send them 35 | through a login flow. To do this we need some 36 | information from our API console project. 37 | ************************************************/ 38 | $client = new Google_Client(); 39 | $client->setClientId($client_id); 40 | $client->setClientSecret($client_secret); 41 | $client->setRedirectUri($redirect_uri); 42 | $client->addScope("https://www.googleapis.com/auth/drive"); 43 | $client->addScope("https://www.googleapis.com/auth/youtube"); 44 | 45 | /************************************************ 46 | We are going to create both YouTube and Drive 47 | services, and query both. 48 | ************************************************/ 49 | $yt_service = new Google_Service_YouTube($client); 50 | $dr_service = new Google_Service_Drive($client); 51 | 52 | 53 | /************************************************ 54 | Boilerplate auth management - see 55 | user-example.php for details. 56 | ************************************************/ 57 | if (isset($_REQUEST['logout'])) { 58 | unset($_SESSION['access_token']); 59 | } 60 | if (isset($_GET['code'])) { 61 | $client->authenticate($_GET['code']); 62 | $_SESSION['access_token'] = $client->getAccessToken(); 63 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 64 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); 65 | } 66 | 67 | if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { 68 | $client->setAccessToken($_SESSION['access_token']); 69 | } else { 70 | $authUrl = $client->createAuthUrl(); 71 | } 72 | 73 | /************************************************ 74 | If we're signed in, retrieve channels from YouTube 75 | and a list of files from Drive. 76 | ************************************************/ 77 | if ($client->getAccessToken()) { 78 | $_SESSION['access_token'] = $client->getAccessToken(); 79 | 80 | $dr_results = $dr_service->files->listFiles(array('maxResults' => 10)); 81 | 82 | $yt_channels = $yt_service->channels->listChannels('contentDetails', array("mine" => true)); 83 | $likePlaylist = $yt_channels[0]->contentDetails->relatedPlaylists->likes; 84 | $yt_results = $yt_service->playlistItems->listPlaylistItems( 85 | "snippet", 86 | array("playlistId" => $likePlaylist) 87 | ); 88 | } 89 | 90 | echo pageHeader("User Query - Multiple APIs"); 91 | if ( 92 | $client_id == '' 93 | || $client_secret == '' 94 | || $redirect_uri == '') { 95 | echo missingClientSecretsWarning(); 96 | } 97 | ?> 98 |
99 |
100 | Connect Me!"; 103 | } else { 104 | echo "

Results Of Drive List:

"; 105 | foreach ($dr_results as $item) { 106 | echo $item->title, "
\n"; 107 | } 108 | 109 | echo "

Results Of YouTube Likes:

"; 110 | foreach ($yt_results as $item) { 111 | echo $item['snippet']['title'], "
\n"; 112 | } 113 | } ?> 114 |
115 |
116 | '; //Client ID 40 | $service_account_name = ''; //Email Address 41 | $key_file_location = ''; //key.p12 42 | 43 | echo pageHeader("Service Account Access"); 44 | if ($client_id == '' 45 | || !strlen($service_account_name) 46 | || !strlen($key_file_location)) { 47 | echo missingServiceAccountDetailsWarning(); 48 | } 49 | 50 | $client = new Google_Client(); 51 | $client->setApplicationName("Client_Library_Examples"); 52 | $service = new Google_Service_Books($client); 53 | 54 | /************************************************ 55 | If we have an access token, we can carry on. 56 | Otherwise, we'll get one with the help of an 57 | assertion credential. In other examples the list 58 | of scopes was managed by the Client, but here 59 | we have to list them manually. We also supply 60 | the service account 61 | ************************************************/ 62 | if (isset($_SESSION['service_token'])) { 63 | $client->setAccessToken($_SESSION['service_token']); 64 | } 65 | $key = file_get_contents($key_file_location); 66 | $cred = new Google_Auth_AssertionCredentials( 67 | $service_account_name, 68 | array('https://www.googleapis.com/auth/books'), 69 | $key 70 | ); 71 | $client->setAssertionCredentials($cred); 72 | if ($client->getAuth()->isAccessTokenExpired()) { 73 | $client->getAuth()->refreshTokenWithAssertion($cred); 74 | } 75 | $_SESSION['service_token'] = $client->getAccessToken(); 76 | 77 | /************************************************ 78 | We're just going to make the same call as in the 79 | simple query as an example. 80 | ************************************************/ 81 | $optParams = array('filter' => 'free-ebooks'); 82 | $results = $service->volumes->listVolumes('Henry David Thoreau', $optParams); 83 | echo "

Results Of Call:

"; 84 | foreach ($results as $item) { 85 | echo $item['volumeInfo']['title'], "
\n"; 86 | } 87 | 88 | echo pageFooter(__FILE__); 89 | -------------------------------------------------------------------------------- /google-api-php-client/examples/simple-query.php: -------------------------------------------------------------------------------- 1 | setApplicationName("Client_Library_Examples"); 38 | $apiKey = ""; // Change this line. 39 | // Warn if the API key isn't changed. 40 | if ($apiKey == '') { 41 | echo missingApiKeyWarning(); 42 | } 43 | $client->setDeveloperKey($apiKey); 44 | 45 | $service = new Google_Service_Books($client); 46 | 47 | /************************************************ 48 | We make a call to our service, which will 49 | normally map to the structure of the API. 50 | In this case $service is Books API, the 51 | resource is volumes, and the method is 52 | listVolumes. We pass it a required parameters 53 | (the query), and an array of named optional 54 | parameters. 55 | ************************************************/ 56 | $optParams = array('filter' => 'free-ebooks'); 57 | $results = $service->volumes->listVolumes('Henry David Thoreau', $optParams); 58 | 59 | /************************************************ 60 | This call returns a list of volumes, so we 61 | can iterate over them as normal with any 62 | array. 63 | Some calls will return a single item which we 64 | can immediately use. The individual responses 65 | are typed as Google_Service_Books_Volume, but 66 | can be treated as an array. 67 | ***********************************************/ 68 | echo "

Results Of Call:

"; 69 | foreach ($results as $item) { 70 | echo $item['volumeInfo']['title'], "
\n"; 71 | } 72 | 73 | /************************************************ 74 | This is an example of deferring a call. 75 | ***********************************************/ 76 | $client->setDefer(true); 77 | $optParams = array('filter' => 'free-ebooks'); 78 | $request = $service->volumes->listVolumes('Henry David Thoreau', $optParams); 79 | $results = $client->execute($request); 80 | 81 | echo "

Results Of Deferred Call:

"; 82 | foreach ($results as $item) { 83 | echo $item['volumeInfo']['title'], "
\n"; 84 | } 85 | 86 | echo pageFooter(__FILE__); 87 | -------------------------------------------------------------------------------- /google-api-php-client/examples/simplefileupload.php: -------------------------------------------------------------------------------- 1 | '; 39 | $client_secret = ''; 40 | $redirect_uri = ''; 41 | 42 | $client = new Google_Client(); 43 | $client->setClientId($client_id); 44 | $client->setClientSecret($client_secret); 45 | $client->setRedirectUri($redirect_uri); 46 | $client->addScope("https://www.googleapis.com/auth/drive"); 47 | $service = new Google_Service_Drive($client); 48 | 49 | if (isset($_REQUEST['logout'])) { 50 | unset($_SESSION['upload_token']); 51 | } 52 | 53 | if (isset($_GET['code'])) { 54 | $client->authenticate($_GET['code']); 55 | $_SESSION['upload_token'] = $client->getAccessToken(); 56 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 57 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); 58 | } 59 | 60 | if (isset($_SESSION['upload_token']) && $_SESSION['upload_token']) { 61 | $client->setAccessToken($_SESSION['upload_token']); 62 | if ($client->isAccessTokenExpired()) { 63 | unset($_SESSION['upload_token']); 64 | } 65 | } else { 66 | $authUrl = $client->createAuthUrl(); 67 | } 68 | 69 | /************************************************ 70 | If we're signed in then lets try to upload our 71 | file. For larger files, see fileupload.php. 72 | ************************************************/ 73 | if ($client->getAccessToken()) { 74 | // This is uploading a file directly, with no metadata associated. 75 | $file = new Google_Service_Drive_DriveFile(); 76 | $result = $service->files->insert( 77 | $file, 78 | array( 79 | 'data' => file_get_contents(TESTFILE), 80 | 'mimeType' => 'application/octet-stream', 81 | 'uploadType' => 'media' 82 | ) 83 | ); 84 | 85 | // Now lets try and send the metadata as well using multipart! 86 | $file = new Google_Service_Drive_DriveFile(); 87 | $file->setTitle("Hello World!"); 88 | $result2 = $service->files->insert( 89 | $file, 90 | array( 91 | 'data' => file_get_contents(TESTFILE), 92 | 'mimeType' => 'application/octet-stream', 93 | 'uploadType' => 'multipart' 94 | ) 95 | ); 96 | } 97 | 98 | echo pageHeader("File Upload - Uploading a small file"); 99 | if ( 100 | $client_id == '' 101 | || $client_secret == '' 102 | || $redirect_uri == '') { 103 | echo missingClientSecretsWarning(); 104 | } 105 | ?> 106 |
107 |
108 | Connect Me!"; 111 | } 112 | ?> 113 |
114 | 115 |
116 | title); 119 | var_dump($result2->title); 120 | } 121 | ?> 122 |
123 |
124 | 13 | 14 | 15 | " . $title . " 16 | 17 | 18 | \n"; 19 | if ($_SERVER['PHP_SELF'] != "/index.php") { 20 | $ret .= "

Back

"; 21 | } 22 | $ret .= "

" . $title . "

"; 23 | } 24 | return $ret; 25 | } 26 | 27 | 28 | function pageFooter($file = null) 29 | { 30 | $ret = ""; 31 | if (isWebRequest()) { 32 | // Echo the code if in an example. 33 | if ($file) { 34 | $ret .= "

Code:

"; 35 | $ret .= "
";
36 |       $ret .= htmlspecialchars(file_get_contents($file));
37 |       $ret .= "
"; 38 | } 39 | $ret .= ""; 40 | } 41 | return $ret; 42 | } 43 | 44 | function missingApiKeyWarning() 45 | { 46 | $ret = ""; 47 | if (isWebRequest()) { 48 | $ret = " 49 |

50 | Warning: You need to set a Simple API Access key from the 51 | Google API console 52 |

"; 53 | } else { 54 | $ret = "Warning: You need to set a Simple API Access key from the Google API console:"; 55 | $ret .= "\nhttp://developers.google.com/console"; 56 | } 57 | return $ret; 58 | } 59 | 60 | function missingClientSecretsWarning() 61 | { 62 | $ret = ""; 63 | if (isWebRequest()) { 64 | $ret = " 65 |

66 | Warning: You need to set Client ID, Client Secret and Redirect URI from the 67 | Google API console 68 |

"; 69 | } else { 70 | $ret = "Warning: You need to set Client ID, Client Secret and Redirect URI from the"; 71 | $ret .= "Google API console:\nhttp://developers.google.com/console"; 72 | } 73 | return $ret; 74 | } 75 | 76 | function missingServiceAccountDetailsWarning() 77 | { 78 | $ret = ""; 79 | if (isWebRequest()) { 80 | $ret = " 81 |

82 | Warning: You need to set Client ID, Email address and the location of the Key from the 83 | Google API console 84 |

"; 85 | } else { 86 | $ret = "Warning: You need to set Client ID, Email address and the location of the Key from the"; 87 | $ret .= "Google API console:\nhttp://developers.google.com/console"; 88 | } 89 | return $ret; 90 | } 91 | -------------------------------------------------------------------------------- /google-api-php-client/examples/user-example.php: -------------------------------------------------------------------------------- 1 | '; 28 | $client_secret = ''; 29 | $redirect_uri = ''; 30 | 31 | /************************************************ 32 | Make an API request on behalf of a user. In 33 | this case we need to have a valid OAuth 2.0 34 | token for the user, so we need to send them 35 | through a login flow. To do this we need some 36 | information from our API console project. 37 | ************************************************/ 38 | $client = new Google_Client(); 39 | $client->setClientId($client_id); 40 | $client->setClientSecret($client_secret); 41 | $client->setRedirectUri($redirect_uri); 42 | $client->addScope("https://www.googleapis.com/auth/urlshortener"); 43 | 44 | /************************************************ 45 | When we create the service here, we pass the 46 | client to it. The client then queries the service 47 | for the required scopes, and uses that when 48 | generating the authentication URL later. 49 | ************************************************/ 50 | $service = new Google_Service_Urlshortener($client); 51 | 52 | /************************************************ 53 | If we're logging out we just need to clear our 54 | local access token in this case 55 | ************************************************/ 56 | if (isset($_REQUEST['logout'])) { 57 | unset($_SESSION['access_token']); 58 | } 59 | 60 | /************************************************ 61 | If we have a code back from the OAuth 2.0 flow, 62 | we need to exchange that with the authenticate() 63 | function. We store the resultant access token 64 | bundle in the session, and redirect to ourself. 65 | ************************************************/ 66 | if (isset($_GET['code'])) { 67 | $client->authenticate($_GET['code']); 68 | $_SESSION['access_token'] = $client->getAccessToken(); 69 | $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 70 | header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); 71 | } 72 | 73 | /************************************************ 74 | If we have an access token, we can make 75 | requests, else we generate an authentication URL. 76 | ************************************************/ 77 | if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { 78 | $client->setAccessToken($_SESSION['access_token']); 79 | } else { 80 | $authUrl = $client->createAuthUrl(); 81 | } 82 | 83 | /************************************************ 84 | If we're signed in and have a request to shorten 85 | a URL, then we create a new URL object, set the 86 | unshortened URL, and call the 'insert' method on 87 | the 'url' resource. Note that we re-store the 88 | access_token bundle, just in case anything 89 | changed during the request - the main thing that 90 | might happen here is the access token itself is 91 | refreshed if the application has offline access. 92 | ************************************************/ 93 | if ($client->getAccessToken() && isset($_GET['url'])) { 94 | $url = new Google_Service_Urlshortener_Url(); 95 | $url->longUrl = $_GET['url']; 96 | $short = $service->url->insert($url); 97 | $_SESSION['access_token'] = $client->getAccessToken(); 98 | } 99 | 100 | echo pageHeader("User Query - URL Shortener"); 101 | if ( 102 | $client_id == '' 103 | || $client_secret == '' 104 | || $redirect_uri == '') { 105 | echo missingClientSecretsWarning(); 106 | } 107 | ?> 108 |
109 |
110 | Connect Me!"; 113 | } else { 114 | echo << 116 | 117 | 118 | 119 | Logout 120 | END; 121 | } 122 | ?> 123 |
124 | 125 |
126 | 131 |
132 |
133 | 2 | 6 | 7 | 8 | tests/youtube 9 | 10 | 11 | tests/tasks 12 | 13 | 14 | tests/pagespeed 15 | 16 | 17 | tests/urlshortener 18 | 19 | 20 | tests/plus 21 | 22 | 23 | tests/adsense 24 | 25 | 26 | tests/general 27 | 28 | 29 | 30 | 31 | tests 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Auth/Abstract.php: -------------------------------------------------------------------------------- 1 | 23 | * 24 | */ 25 | abstract class Google_Auth_Abstract 26 | { 27 | /** 28 | * An utility function that first calls $this->auth->sign($request) and then 29 | * executes makeRequest() on that signed request. Used for when a request 30 | * should be authenticated 31 | * @param Google_Http_Request $request 32 | * @return Google_Http_Request $request 33 | */ 34 | abstract public function authenticatedRequest(Google_Http_Request $request); 35 | abstract public function sign(Google_Http_Request $request); 36 | } 37 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Auth/AppIdentity.php: -------------------------------------------------------------------------------- 1 | client = $client; 41 | } 42 | 43 | /** 44 | * Retrieve an access token for the scopes supplied. 45 | */ 46 | public function authenticateForScope($scopes) 47 | { 48 | if ($this->token && $this->tokenScopes == $scopes) { 49 | return $this->token; 50 | } 51 | 52 | $cacheKey = self::CACHE_PREFIX; 53 | if (is_string($scopes)) { 54 | $cacheKey .= $scopes; 55 | } else if (is_array($scopes)) { 56 | $cacheKey .= implode(":", $scopes); 57 | } 58 | 59 | $this->token = $this->client->getCache()->get($cacheKey); 60 | if (!$this->token) { 61 | $this->retrieveToken($scopes, $cacheKey); 62 | } 63 | else if ($this->token['expiration_time'] < time()) { 64 | $this->client->getCache()->delete($cacheKey); 65 | $this->retrieveToken($scopes, $cacheKey); 66 | } 67 | 68 | $this->tokenScopes = $scopes; 69 | return $this->token; 70 | } 71 | 72 | /** 73 | * Retrieve a new access token and store it in cache 74 | * @param mixed $scopes 75 | * @param string $cacheKey 76 | */ 77 | private function retrieveToken($scopes, $cacheKey) 78 | { 79 | $this->token = AppIdentityService::getAccessToken($scopes); 80 | if ($this->token) { 81 | $this->client->getCache()->set( 82 | $cacheKey, 83 | $this->token 84 | ); 85 | } 86 | } 87 | 88 | /** 89 | * Perform an authenticated / signed apiHttpRequest. 90 | * This function takes the apiHttpRequest, calls apiAuth->sign on it 91 | * (which can modify the request in what ever way fits the auth mechanism) 92 | * and then calls apiCurlIO::makeRequest on the signed request 93 | * 94 | * @param Google_Http_Request $request 95 | * @return Google_Http_Request The resulting HTTP response including the 96 | * responseHttpCode, responseHeaders and responseBody. 97 | */ 98 | public function authenticatedRequest(Google_Http_Request $request) 99 | { 100 | $request = $this->sign($request); 101 | return $this->client->getIo()->makeRequest($request); 102 | } 103 | 104 | public function sign(Google_Http_Request $request) 105 | { 106 | if (!$this->token) { 107 | // No token, so nothing to do. 108 | return $request; 109 | } 110 | 111 | $this->client->getLogger()->debug('App Identity authentication'); 112 | 113 | // Add the OAuth2 header to the request 114 | $request->setRequestHeaders( 115 | array('Authorization' => 'Bearer ' . $this->token['access_token']) 116 | ); 117 | 118 | return $request; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Auth/AssertionCredentials.php: -------------------------------------------------------------------------------- 1 | 24 | */ 25 | class Google_Auth_AssertionCredentials 26 | { 27 | const MAX_TOKEN_LIFETIME_SECS = 3600; 28 | 29 | public $serviceAccountName; 30 | public $scopes; 31 | public $privateKey; 32 | public $privateKeyPassword; 33 | public $assertionType; 34 | public $sub; 35 | /** 36 | * @deprecated 37 | * @link http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-06 38 | */ 39 | public $prn; 40 | private $useCache; 41 | 42 | /** 43 | * @param $serviceAccountName 44 | * @param $scopes array List of scopes 45 | * @param $privateKey 46 | * @param string $privateKeyPassword 47 | * @param string $assertionType 48 | * @param bool|string $sub The email address of the user for which the 49 | * application is requesting delegated access. 50 | * @param bool useCache Whether to generate a cache key and allow 51 | * automatic caching of the generated token. 52 | */ 53 | public function __construct( 54 | $serviceAccountName, 55 | $scopes, 56 | $privateKey, 57 | $privateKeyPassword = 'notasecret', 58 | $assertionType = 'http://oauth.net/grant_type/jwt/1.0/bearer', 59 | $sub = false, 60 | $useCache = true 61 | ) { 62 | $this->serviceAccountName = $serviceAccountName; 63 | $this->scopes = is_string($scopes) ? $scopes : implode(' ', $scopes); 64 | $this->privateKey = $privateKey; 65 | $this->privateKeyPassword = $privateKeyPassword; 66 | $this->assertionType = $assertionType; 67 | $this->sub = $sub; 68 | $this->prn = $sub; 69 | $this->useCache = $useCache; 70 | } 71 | 72 | /** 73 | * Generate a unique key to represent this credential. 74 | * @return string 75 | */ 76 | public function getCacheKey() 77 | { 78 | if (!$this->useCache) { 79 | return false; 80 | } 81 | $h = $this->sub; 82 | $h .= $this->assertionType; 83 | $h .= $this->privateKey; 84 | $h .= $this->scopes; 85 | $h .= $this->serviceAccountName; 86 | return md5($h); 87 | } 88 | 89 | public function generateAssertion() 90 | { 91 | $now = time(); 92 | 93 | $jwtParams = array( 94 | 'aud' => Google_Auth_OAuth2::OAUTH2_TOKEN_URI, 95 | 'scope' => $this->scopes, 96 | 'iat' => $now, 97 | 'exp' => $now + self::MAX_TOKEN_LIFETIME_SECS, 98 | 'iss' => $this->serviceAccountName, 99 | ); 100 | 101 | if ($this->sub !== false) { 102 | $jwtParams['sub'] = $this->sub; 103 | } else if ($this->prn !== false) { 104 | $jwtParams['prn'] = $this->prn; 105 | } 106 | 107 | return $this->makeSignedJwt($jwtParams); 108 | } 109 | 110 | /** 111 | * Creates a signed JWT. 112 | * @param array $payload 113 | * @return string The signed JWT. 114 | */ 115 | private function makeSignedJwt($payload) 116 | { 117 | $header = array('typ' => 'JWT', 'alg' => 'RS256'); 118 | 119 | $payload = json_encode($payload); 120 | // Handle some overzealous escaping in PHP json that seemed to cause some errors 121 | // with claimsets. 122 | $payload = str_replace('\/', '/', $payload); 123 | 124 | $segments = array( 125 | Google_Utils::urlSafeB64Encode(json_encode($header)), 126 | Google_Utils::urlSafeB64Encode($payload) 127 | ); 128 | 129 | $signingInput = implode('.', $segments); 130 | $signer = new Google_Signer_P12($this->privateKey, $this->privateKeyPassword); 131 | $signature = $signer->sign($signingInput); 132 | $segments[] = Google_Utils::urlSafeB64Encode($signature); 133 | 134 | return implode(".", $segments); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Auth/Exception.php: -------------------------------------------------------------------------------- 1 | 24 | */ 25 | class Google_Auth_LoginTicket 26 | { 27 | const USER_ATTR = "sub"; 28 | 29 | // Information from id token envelope. 30 | private $envelope; 31 | 32 | // Information from id token payload. 33 | private $payload; 34 | 35 | /** 36 | * Creates a user based on the supplied token. 37 | * 38 | * @param string $envelope Header from a verified authentication token. 39 | * @param string $payload Information from a verified authentication token. 40 | */ 41 | public function __construct($envelope, $payload) 42 | { 43 | $this->envelope = $envelope; 44 | $this->payload = $payload; 45 | } 46 | 47 | /** 48 | * Returns the numeric identifier for the user. 49 | * @throws Google_Auth_Exception 50 | * @return 51 | */ 52 | public function getUserId() 53 | { 54 | if (array_key_exists(self::USER_ATTR, $this->payload)) { 55 | return $this->payload[self::USER_ATTR]; 56 | } 57 | throw new Google_Auth_Exception("No user_id in token"); 58 | } 59 | 60 | /** 61 | * Returns attributes from the login ticket. This can contain 62 | * various information about the user session. 63 | * @return array 64 | */ 65 | public function getAttributes() 66 | { 67 | return array("envelope" => $this->envelope, "payload" => $this->payload); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Auth/Simple.php: -------------------------------------------------------------------------------- 1 | 25 | * @author Chirag Shah 26 | */ 27 | class Google_Auth_Simple extends Google_Auth_Abstract 28 | { 29 | private $key = null; 30 | private $client; 31 | 32 | public function __construct(Google_Client $client, $config = null) 33 | { 34 | $this->client = $client; 35 | } 36 | 37 | /** 38 | * Perform an authenticated / signed apiHttpRequest. 39 | * This function takes the apiHttpRequest, calls apiAuth->sign on it 40 | * (which can modify the request in what ever way fits the auth mechanism) 41 | * and then calls apiCurlIO::makeRequest on the signed request 42 | * 43 | * @param Google_Http_Request $request 44 | * @return Google_Http_Request The resulting HTTP response including the 45 | * responseHttpCode, responseHeaders and responseBody. 46 | */ 47 | public function authenticatedRequest(Google_Http_Request $request) 48 | { 49 | $request = $this->sign($request); 50 | return $this->io->makeRequest($request); 51 | } 52 | 53 | public function sign(Google_Http_Request $request) 54 | { 55 | $key = $this->client->getClassConfig($this, 'developer_key'); 56 | if ($key) { 57 | $this->client->getLogger()->debug( 58 | 'Simple API Access developer key authentication' 59 | ); 60 | $request->setQueryParam('key', $key); 61 | } 62 | return $request; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Cache/Abstract.php: -------------------------------------------------------------------------------- 1 | 22 | */ 23 | abstract class Google_Cache_Abstract 24 | { 25 | 26 | abstract public function __construct(Google_Client $client); 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 public 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 public function set($key, $value); 46 | 47 | /** 48 | * Removes the key/data pair for the given $key 49 | * 50 | * @param String $key 51 | */ 52 | abstract public function delete($key); 53 | } 54 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Cache/Apc.php: -------------------------------------------------------------------------------- 1 | 27 | */ 28 | class Google_Cache_Apc extends Google_Cache_Abstract 29 | { 30 | /** 31 | * @var Google_Client the current client 32 | */ 33 | private $client; 34 | 35 | public function __construct(Google_Client $client) 36 | { 37 | if (! function_exists('apc_add') ) { 38 | $error = "Apc functions not available"; 39 | 40 | $client->getLogger()->error($error); 41 | throw new Google_Cache_Exception($error); 42 | } 43 | 44 | $this->client = $client; 45 | } 46 | 47 | /** 48 | * @inheritDoc 49 | */ 50 | public function get($key, $expiration = false) 51 | { 52 | $ret = apc_fetch($key); 53 | if ($ret === false) { 54 | $this->client->getLogger()->debug( 55 | 'APC cache miss', 56 | array('key' => $key) 57 | ); 58 | return false; 59 | } 60 | if (is_numeric($expiration) && (time() - $ret['time'] > $expiration)) { 61 | $this->client->getLogger()->debug( 62 | 'APC cache miss (expired)', 63 | array('key' => $key, 'var' => $ret) 64 | ); 65 | $this->delete($key); 66 | return false; 67 | } 68 | 69 | $this->client->getLogger()->debug( 70 | 'APC cache hit', 71 | array('key' => $key, 'var' => $ret) 72 | ); 73 | 74 | return $ret['data']; 75 | } 76 | 77 | /** 78 | * @inheritDoc 79 | */ 80 | public function set($key, $value) 81 | { 82 | $var = array('time' => time(), 'data' => $value); 83 | $rc = apc_store($key, $var); 84 | 85 | if ($rc == false) { 86 | $this->client->getLogger()->error( 87 | 'APC cache set failed', 88 | array('key' => $key, 'var' => $var) 89 | ); 90 | throw new Google_Cache_Exception("Couldn't store data"); 91 | } 92 | 93 | $this->client->getLogger()->debug( 94 | 'APC cache set', 95 | array('key' => $key, 'var' => $var) 96 | ); 97 | } 98 | 99 | /** 100 | * @inheritDoc 101 | * @param String $key 102 | */ 103 | public function delete($key) 104 | { 105 | $this->client->getLogger()->debug( 106 | 'APC cache delete', 107 | array('key' => $key) 108 | ); 109 | apc_delete($key); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Cache/Exception.php: -------------------------------------------------------------------------------- 1 | 27 | */ 28 | class Google_Cache_File extends Google_Cache_Abstract 29 | { 30 | const MAX_LOCK_RETRIES = 10; 31 | private $path; 32 | private $fh; 33 | 34 | /** 35 | * @var Google_Client the current client 36 | */ 37 | private $client; 38 | 39 | public function __construct(Google_Client $client) 40 | { 41 | $this->client = $client; 42 | $this->path = $this->client->getClassConfig($this, 'directory'); 43 | } 44 | 45 | public function get($key, $expiration = false) 46 | { 47 | $storageFile = $this->getCacheFile($key); 48 | $data = false; 49 | 50 | if (!file_exists($storageFile)) { 51 | $this->client->getLogger()->debug( 52 | 'File cache miss', 53 | array('key' => $key, 'file' => $storageFile) 54 | ); 55 | return false; 56 | } 57 | 58 | if ($expiration) { 59 | $mtime = filemtime($storageFile); 60 | if ((time() - $mtime) >= $expiration) { 61 | $this->client->getLogger()->debug( 62 | 'File cache miss (expired)', 63 | array('key' => $key, 'file' => $storageFile) 64 | ); 65 | $this->delete($key); 66 | return false; 67 | } 68 | } 69 | 70 | if ($this->acquireReadLock($storageFile)) { 71 | $data = fread($this->fh, filesize($storageFile)); 72 | $data = unserialize($data); 73 | $this->unlock($storageFile); 74 | } 75 | 76 | $this->client->getLogger()->debug( 77 | 'File cache hit', 78 | array('key' => $key, 'file' => $storageFile, 'var' => $data) 79 | ); 80 | 81 | return $data; 82 | } 83 | 84 | public function set($key, $value) 85 | { 86 | $storageFile = $this->getWriteableCacheFile($key); 87 | if ($this->acquireWriteLock($storageFile)) { 88 | // We serialize the whole request object, since we don't only want the 89 | // responseContent but also the postBody used, headers, size, etc. 90 | $data = serialize($value); 91 | $result = fwrite($this->fh, $data); 92 | $this->unlock($storageFile); 93 | 94 | $this->client->getLogger()->debug( 95 | 'File cache set', 96 | array('key' => $key, 'file' => $storageFile, 'var' => $value) 97 | ); 98 | } else { 99 | $this->client->getLogger()->notice( 100 | 'File cache set failed', 101 | array('key' => $key, 'file' => $storageFile) 102 | ); 103 | } 104 | } 105 | 106 | public function delete($key) 107 | { 108 | $file = $this->getCacheFile($key); 109 | if (file_exists($file) && !unlink($file)) { 110 | $this->client->getLogger()->error( 111 | 'File cache delete failed', 112 | array('key' => $key, 'file' => $file) 113 | ); 114 | throw new Google_Cache_Exception("Cache file could not be deleted"); 115 | } 116 | 117 | $this->client->getLogger()->debug( 118 | 'File cache delete', 119 | array('key' => $key, 'file' => $file) 120 | ); 121 | } 122 | 123 | private function getWriteableCacheFile($file) 124 | { 125 | return $this->getCacheFile($file, true); 126 | } 127 | 128 | private function getCacheFile($file, $forWrite = false) 129 | { 130 | return $this->getCacheDir($file, $forWrite) . '/' . md5($file); 131 | } 132 | 133 | private function getCacheDir($file, $forWrite) 134 | { 135 | // use the first 2 characters of the hash as a directory prefix 136 | // this should prevent slowdowns due to huge directory listings 137 | // and thus give some basic amount of scalability 138 | $storageDir = $this->path . '/' . substr(md5($file), 0, 2); 139 | if ($forWrite && ! is_dir($storageDir)) { 140 | if (! mkdir($storageDir, 0755, true)) { 141 | $this->client->getLogger()->error( 142 | 'File cache creation failed', 143 | array('dir' => $storageDir) 144 | ); 145 | throw new Google_Cache_Exception("Could not create storage directory: $storageDir"); 146 | } 147 | } 148 | return $storageDir; 149 | } 150 | 151 | private function acquireReadLock($storageFile) 152 | { 153 | return $this->acquireLock(LOCK_SH, $storageFile); 154 | } 155 | 156 | private function acquireWriteLock($storageFile) 157 | { 158 | $rc = $this->acquireLock(LOCK_EX, $storageFile); 159 | if (!$rc) { 160 | $this->client->getLogger()->notice( 161 | 'File cache write lock failed', 162 | array('file' => $storageFile) 163 | ); 164 | $this->delete($storageFile); 165 | } 166 | return $rc; 167 | } 168 | 169 | private function acquireLock($type, $storageFile) 170 | { 171 | $mode = $type == LOCK_EX ? "w" : "r"; 172 | $this->fh = fopen($storageFile, $mode); 173 | $count = 0; 174 | while (!flock($this->fh, $type | LOCK_NB)) { 175 | // Sleep for 10ms. 176 | usleep(10000); 177 | if (++$count < self::MAX_LOCK_RETRIES) { 178 | return false; 179 | } 180 | } 181 | return true; 182 | } 183 | 184 | public function unlock($storageFile) 185 | { 186 | if ($this->fh) { 187 | flock($this->fh, LOCK_UN); 188 | } 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Cache/Memcache.php: -------------------------------------------------------------------------------- 1 | 29 | */ 30 | class Google_Cache_Memcache extends Google_Cache_Abstract 31 | { 32 | private $connection = false; 33 | private $mc = false; 34 | private $host; 35 | private $port; 36 | 37 | /** 38 | * @var Google_Client the current client 39 | */ 40 | private $client; 41 | 42 | public function __construct(Google_Client $client) 43 | { 44 | if (!function_exists('memcache_connect') && !class_exists("Memcached")) { 45 | $error = "Memcache functions not available"; 46 | 47 | $client->getLogger()->error($error); 48 | throw new Google_Cache_Exception($error); 49 | } 50 | 51 | $this->client = $client; 52 | 53 | if ($client->isAppEngine()) { 54 | // No credentials needed for GAE. 55 | $this->mc = new Memcached(); 56 | $this->connection = true; 57 | } else { 58 | $this->host = $client->getClassConfig($this, 'host'); 59 | $this->port = $client->getClassConfig($this, 'port'); 60 | if (empty($this->host) || (empty($this->port) && (string) $this->port != "0")) { 61 | $error = "You need to supply a valid memcache host and port"; 62 | 63 | $client->getLogger()->error($error); 64 | throw new Google_Cache_Exception($error); 65 | } 66 | } 67 | } 68 | 69 | /** 70 | * @inheritDoc 71 | */ 72 | public function get($key, $expiration = false) 73 | { 74 | $this->connect(); 75 | $ret = false; 76 | if ($this->mc) { 77 | $ret = $this->mc->get($key); 78 | } else { 79 | $ret = memcache_get($this->connection, $key); 80 | } 81 | if ($ret === false) { 82 | $this->client->getLogger()->debug( 83 | 'Memcache cache miss', 84 | array('key' => $key) 85 | ); 86 | return false; 87 | } 88 | if (is_numeric($expiration) && (time() - $ret['time'] > $expiration)) { 89 | $this->client->getLogger()->debug( 90 | 'Memcache cache miss (expired)', 91 | array('key' => $key, 'var' => $ret) 92 | ); 93 | $this->delete($key); 94 | return false; 95 | } 96 | 97 | $this->client->getLogger()->debug( 98 | 'Memcache cache hit', 99 | array('key' => $key, 'var' => $ret) 100 | ); 101 | 102 | return $ret['data']; 103 | } 104 | 105 | /** 106 | * @inheritDoc 107 | * @param string $key 108 | * @param string $value 109 | * @throws Google_Cache_Exception 110 | */ 111 | public function set($key, $value) 112 | { 113 | $this->connect(); 114 | // we store it with the cache_time default expiration so objects will at 115 | // least get cleaned eventually. 116 | $data = array('time' => time(), 'data' => $value); 117 | $rc = false; 118 | if ($this->mc) { 119 | $rc = $this->mc->set($key, $data); 120 | } else { 121 | $rc = memcache_set($this->connection, $key, $data, false); 122 | } 123 | if ($rc == false) { 124 | $this->client->getLogger()->error( 125 | 'Memcache cache set failed', 126 | array('key' => $key, 'var' => $data) 127 | ); 128 | 129 | throw new Google_Cache_Exception("Couldn't store data in cache"); 130 | } 131 | 132 | $this->client->getLogger()->debug( 133 | 'Memcache cache set', 134 | array('key' => $key, 'var' => $data) 135 | ); 136 | } 137 | 138 | /** 139 | * @inheritDoc 140 | * @param String $key 141 | */ 142 | public function delete($key) 143 | { 144 | $this->connect(); 145 | if ($this->mc) { 146 | $this->mc->delete($key, 0); 147 | } else { 148 | memcache_delete($this->connection, $key, 0); 149 | } 150 | 151 | $this->client->getLogger()->debug( 152 | 'Memcache cache delete', 153 | array('key' => $key) 154 | ); 155 | } 156 | 157 | /** 158 | * Lazy initialiser for memcache connection. Uses pconnect for to take 159 | * advantage of the persistence pool where possible. 160 | */ 161 | private function connect() 162 | { 163 | if ($this->connection) { 164 | return; 165 | } 166 | 167 | if (class_exists("Memcached")) { 168 | $this->mc = new Memcached(); 169 | $this->mc->addServer($this->host, $this->port); 170 | $this->connection = true; 171 | } else { 172 | $this->connection = memcache_pconnect($this->host, $this->port); 173 | } 174 | 175 | if (! $this->connection) { 176 | $error = "Couldn't connect to memcache server"; 177 | 178 | $this->client->getLogger()->error($error); 179 | throw new Google_Cache_Exception($error); 180 | } 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Cache/Null.php: -------------------------------------------------------------------------------- 1 | modelData[$this->collection_key]) 17 | && is_array($this->modelData[$this->collection_key])) { 18 | reset($this->modelData[$this->collection_key]); 19 | } 20 | } 21 | 22 | public function current() 23 | { 24 | $this->coerceType($this->key()); 25 | if (is_array($this->modelData[$this->collection_key])) { 26 | return current($this->modelData[$this->collection_key]); 27 | } 28 | } 29 | 30 | public function key() 31 | { 32 | if (isset($this->modelData[$this->collection_key]) 33 | && is_array($this->modelData[$this->collection_key])) { 34 | return key($this->modelData[$this->collection_key]); 35 | } 36 | } 37 | 38 | public function next() 39 | { 40 | return next($this->modelData[$this->collection_key]); 41 | } 42 | 43 | public function valid() 44 | { 45 | $key = $this->key(); 46 | return $key !== null && $key !== false; 47 | } 48 | 49 | public function count() 50 | { 51 | return count($this->modelData[$this->collection_key]); 52 | } 53 | 54 | public function offsetExists ($offset) 55 | { 56 | if (!is_numeric($offset)) { 57 | return parent::offsetExists($offset); 58 | } 59 | return isset($this->modelData[$this->collection_key][$offset]); 60 | } 61 | 62 | public function offsetGet($offset) 63 | { 64 | if (!is_numeric($offset)) { 65 | return parent::offsetGet($offset); 66 | } 67 | $this->coerceType($offset); 68 | return $this->modelData[$this->collection_key][$offset]; 69 | } 70 | 71 | public function offsetSet($offset, $value) 72 | { 73 | if (!is_numeric($offset)) { 74 | return parent::offsetSet($offset, $value); 75 | } 76 | $this->modelData[$this->collection_key][$offset] = $value; 77 | } 78 | 79 | public function offsetUnset($offset) 80 | { 81 | if (!is_numeric($offset)) { 82 | return parent::offsetUnset($offset); 83 | } 84 | unset($this->modelData[$this->collection_key][$offset]); 85 | } 86 | 87 | private function coerceType($offset) 88 | { 89 | $typeKey = $this->keyType($this->collection_key); 90 | if (isset($this->$typeKey) && !is_object($this->modelData[$this->collection_key][$offset])) { 91 | $type = $this->$typeKey; 92 | $this->modelData[$this->collection_key][$offset] = 93 | new $type($this->modelData[$this->collection_key][$offset]); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Exception.php: -------------------------------------------------------------------------------- 1 | 22 | */ 23 | class Google_Http_Batch 24 | { 25 | /** @var string Multipart Boundary. */ 26 | private $boundary; 27 | 28 | /** @var array service requests to be executed. */ 29 | private $requests = array(); 30 | 31 | /** @var Google_Client */ 32 | private $client; 33 | 34 | private $expected_classes = array(); 35 | 36 | private $base_path; 37 | 38 | public function __construct(Google_Client $client, $boundary = false) 39 | { 40 | $this->client = $client; 41 | $this->base_path = $this->client->getBasePath(); 42 | $this->expected_classes = array(); 43 | $boundary = (false == $boundary) ? mt_rand() : $boundary; 44 | $this->boundary = str_replace('"', '', $boundary); 45 | } 46 | 47 | public function add(Google_Http_Request $request, $key = false) 48 | { 49 | if (false == $key) { 50 | $key = mt_rand(); 51 | } 52 | 53 | $this->requests[$key] = $request; 54 | } 55 | 56 | public function execute() 57 | { 58 | $body = ''; 59 | 60 | /** @var Google_Http_Request $req */ 61 | foreach ($this->requests as $key => $req) { 62 | $body .= "--{$this->boundary}\n"; 63 | $body .= $req->toBatchString($key) . "\n"; 64 | $this->expected_classes["response-" . $key] = $req->getExpectedClass(); 65 | } 66 | 67 | $body = rtrim($body); 68 | $body .= "\n--{$this->boundary}--"; 69 | 70 | $url = $this->base_path . '/batch'; 71 | $httpRequest = new Google_Http_Request($url, 'POST'); 72 | $httpRequest->setRequestHeaders( 73 | array('Content-Type' => 'multipart/mixed; boundary=' . $this->boundary) 74 | ); 75 | 76 | $httpRequest->setPostBody($body); 77 | $response = $this->client->getIo()->makeRequest($httpRequest); 78 | 79 | return $this->parseResponse($response); 80 | } 81 | 82 | public function parseResponse(Google_Http_Request $response) 83 | { 84 | $contentType = $response->getResponseHeader('content-type'); 85 | $contentType = explode(';', $contentType); 86 | $boundary = false; 87 | foreach ($contentType as $part) { 88 | $part = (explode('=', $part, 2)); 89 | if (isset($part[0]) && 'boundary' == trim($part[0])) { 90 | $boundary = $part[1]; 91 | } 92 | } 93 | 94 | $body = $response->getResponseBody(); 95 | if ($body) { 96 | $body = str_replace("--$boundary--", "--$boundary", $body); 97 | $parts = explode("--$boundary", $body); 98 | $responses = array(); 99 | 100 | foreach ($parts as $part) { 101 | $part = trim($part); 102 | if (!empty($part)) { 103 | list($metaHeaders, $part) = explode("\r\n\r\n", $part, 2); 104 | $metaHeaders = $this->client->getIo()->getHttpResponseHeaders($metaHeaders); 105 | 106 | $status = substr($part, 0, strpos($part, "\n")); 107 | $status = explode(" ", $status); 108 | $status = $status[1]; 109 | 110 | list($partHeaders, $partBody) = $this->client->getIo()->ParseHttpResponse($part, false); 111 | $response = new Google_Http_Request(""); 112 | $response->setResponseHttpCode($status); 113 | $response->setResponseHeaders($partHeaders); 114 | $response->setResponseBody($partBody); 115 | 116 | // Need content id. 117 | $key = $metaHeaders['content-id']; 118 | 119 | if (isset($this->expected_classes[$key]) && 120 | strlen($this->expected_classes[$key]) > 0) { 121 | $class = $this->expected_classes[$key]; 122 | $response->setExpectedClass($class); 123 | } 124 | 125 | try { 126 | $response = Google_Http_REST::decodeHttpResponse($response, $this->client); 127 | $responses[$key] = $response; 128 | } catch (Google_Service_Exception $e) { 129 | // Store the exception as the response, so successful responses 130 | // can be processed. 131 | $responses[$key] = $e; 132 | } 133 | } 134 | } 135 | 136 | return $responses; 137 | } 138 | 139 | return null; 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Http/REST.php: -------------------------------------------------------------------------------- 1 | 24 | * @author Chirag Shah 25 | */ 26 | class Google_Http_REST 27 | { 28 | /** 29 | * Executes a Google_Http_Request and (if applicable) automatically retries 30 | * when errors occur. 31 | * 32 | * @param Google_Client $client 33 | * @param Google_Http_Request $req 34 | * @return array decoded result 35 | * @throws Google_Service_Exception on server side error (ie: not authenticated, 36 | * invalid or malformed post body, invalid url) 37 | */ 38 | public static function execute(Google_Client $client, Google_Http_Request $req) 39 | { 40 | $runner = new Google_Task_Runner( 41 | $client, 42 | sprintf('%s %s', $req->getRequestMethod(), $req->getUrl()), 43 | array(get_class(), 'doExecute'), 44 | array($client, $req) 45 | ); 46 | 47 | return $runner->run(); 48 | } 49 | 50 | /** 51 | * Executes a Google_Http_Request 52 | * 53 | * @param Google_Client $client 54 | * @param Google_Http_Request $req 55 | * @return array decoded result 56 | * @throws Google_Service_Exception on server side error (ie: not authenticated, 57 | * invalid or malformed post body, invalid url) 58 | */ 59 | public static function doExecute(Google_Client $client, Google_Http_Request $req) 60 | { 61 | $httpRequest = $client->getIo()->makeRequest($req); 62 | $httpRequest->setExpectedClass($req->getExpectedClass()); 63 | return self::decodeHttpResponse($httpRequest, $client); 64 | } 65 | 66 | /** 67 | * Decode an HTTP Response. 68 | * @static 69 | * @throws Google_Service_Exception 70 | * @param Google_Http_Request $response The http response to be decoded. 71 | * @param Google_Client $client 72 | * @return mixed|null 73 | */ 74 | public static function decodeHttpResponse($response, Google_Client $client = null) 75 | { 76 | $code = $response->getResponseHttpCode(); 77 | $body = $response->getResponseBody(); 78 | $decoded = null; 79 | 80 | if ((intVal($code)) >= 300) { 81 | $decoded = json_decode($body, true); 82 | $err = 'Error calling ' . $response->getRequestMethod() . ' ' . $response->getUrl(); 83 | if (isset($decoded['error']) && 84 | isset($decoded['error']['message']) && 85 | isset($decoded['error']['code'])) { 86 | // if we're getting a json encoded error definition, use that instead of the raw response 87 | // body for improved readability 88 | $err .= ": ({$decoded['error']['code']}) {$decoded['error']['message']}"; 89 | } else { 90 | $err .= ": ($code) $body"; 91 | } 92 | 93 | $errors = null; 94 | // Specific check for APIs which don't return error details, such as Blogger. 95 | if (isset($decoded['error']) && isset($decoded['error']['errors'])) { 96 | $errors = $decoded['error']['errors']; 97 | } 98 | 99 | $map = null; 100 | if ($client) { 101 | $client->getLogger()->error( 102 | $err, 103 | array('code' => $code, 'errors' => $errors) 104 | ); 105 | 106 | $map = $client->getClassConfig( 107 | 'Google_Service_Exception', 108 | 'retry_map' 109 | ); 110 | } 111 | throw new Google_Service_Exception($err, $code, null, $errors, $map); 112 | } 113 | 114 | // Only attempt to decode the response, if the response code wasn't (204) 'no content' 115 | if ($code != '204') { 116 | $decoded = json_decode($body, true); 117 | if ($decoded === null || $decoded === "") { 118 | $error = "Invalid json in service response: $body"; 119 | if ($client) { 120 | $client->getLogger()->error($error); 121 | } 122 | throw new Google_Service_Exception($error); 123 | } 124 | 125 | if ($response->getExpectedClass()) { 126 | $class = $response->getExpectedClass(); 127 | $decoded = new $class($decoded); 128 | } 129 | } 130 | return $decoded; 131 | } 132 | 133 | /** 134 | * Parse/expand request parameters and create a fully qualified 135 | * request uri. 136 | * @static 137 | * @param string $servicePath 138 | * @param string $restPath 139 | * @param array $params 140 | * @return string $requestUrl 141 | */ 142 | public static function createRequestUri($servicePath, $restPath, $params) 143 | { 144 | $requestUrl = $servicePath . $restPath; 145 | $uriTemplateVars = array(); 146 | $queryVars = array(); 147 | foreach ($params as $paramName => $paramSpec) { 148 | if ($paramSpec['type'] == 'boolean') { 149 | $paramSpec['value'] = ($paramSpec['value']) ? 'true' : 'false'; 150 | } 151 | if ($paramSpec['location'] == 'path') { 152 | $uriTemplateVars[$paramName] = $paramSpec['value']; 153 | } else if ($paramSpec['location'] == 'query') { 154 | if (isset($paramSpec['repeated']) && is_array($paramSpec['value'])) { 155 | foreach ($paramSpec['value'] as $value) { 156 | $queryVars[] = $paramName . '=' . rawurlencode($value); 157 | } 158 | } else { 159 | $queryVars[] = $paramName . '=' . rawurlencode($paramSpec['value']); 160 | } 161 | } 162 | } 163 | 164 | if (count($uriTemplateVars)) { 165 | $uriTemplateParser = new Google_Utils_URITemplate(); 166 | $requestUrl = $uriTemplateParser->parse($requestUrl, $uriTemplateVars); 167 | } 168 | 169 | if (count($queryVars)) { 170 | $requestUrl .= '?' . implode($queryVars, '&'); 171 | } 172 | 173 | return $requestUrl; 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/IO/Curl.php: -------------------------------------------------------------------------------- 1 | 22 | */ 23 | 24 | require_once realpath(dirname(__FILE__) . '/../../../autoload.php'); 25 | 26 | class Google_IO_Curl extends Google_IO_Abstract 27 | { 28 | // cURL hex representation of version 7.30.0 29 | const NO_QUIRK_VERSION = 0x071E00; 30 | 31 | private $options = array(); 32 | 33 | public function __construct(Google_Client $client) 34 | { 35 | if (!extension_loaded('curl')) { 36 | $error = 'The cURL IO handler requires the cURL extension to be enabled'; 37 | $client->getLogger()->critical($error); 38 | throw new Google_IO_Exception($error); 39 | } 40 | 41 | parent::__construct($client); 42 | } 43 | 44 | /** 45 | * Execute an HTTP Request 46 | * 47 | * @param Google_HttpRequest $request the http request to be executed 48 | * @return Google_HttpRequest http request with the response http code, 49 | * response headers and response body filled in 50 | * @throws Google_IO_Exception on curl or IO error 51 | */ 52 | public function executeRequest(Google_Http_Request $request) 53 | { 54 | $curl = curl_init(); 55 | 56 | if ($request->getPostBody()) { 57 | curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getPostBody()); 58 | } 59 | 60 | $requestHeaders = $request->getRequestHeaders(); 61 | if ($requestHeaders && is_array($requestHeaders)) { 62 | $curlHeaders = array(); 63 | foreach ($requestHeaders as $k => $v) { 64 | $curlHeaders[] = "$k: $v"; 65 | } 66 | curl_setopt($curl, CURLOPT_HTTPHEADER, $curlHeaders); 67 | } 68 | curl_setopt($curl, CURLOPT_URL, $request->getUrl()); 69 | 70 | curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->getRequestMethod()); 71 | curl_setopt($curl, CURLOPT_USERAGENT, $request->getUserAgent()); 72 | 73 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, false); 74 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); 75 | // 1 is CURL_SSLVERSION_TLSv1, which is not always defined in PHP. 76 | curl_setopt($curl, CURLOPT_SSLVERSION, 1); 77 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 78 | curl_setopt($curl, CURLOPT_HEADER, true); 79 | 80 | if ($request->canGzip()) { 81 | curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate'); 82 | } 83 | 84 | foreach ($this->options as $key => $var) { 85 | curl_setopt($curl, $key, $var); 86 | } 87 | 88 | if (!isset($this->options[CURLOPT_CAINFO])) { 89 | curl_setopt($curl, CURLOPT_CAINFO, dirname(__FILE__) . '/cacerts.pem'); 90 | } 91 | 92 | $this->client->getLogger()->debug( 93 | 'cURL request', 94 | array( 95 | 'url' => $request->getUrl(), 96 | 'method' => $request->getRequestMethod(), 97 | 'headers' => $requestHeaders, 98 | 'body' => $request->getPostBody() 99 | ) 100 | ); 101 | 102 | $response = curl_exec($curl); 103 | if ($response === false) { 104 | $error = curl_error($curl); 105 | $code = curl_errno($curl); 106 | $map = $this->client->getClassConfig('Google_IO_Exception', 'retry_map'); 107 | 108 | $this->client->getLogger()->error('cURL ' . $error); 109 | throw new Google_IO_Exception($error, $code, null, $map); 110 | } 111 | $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); 112 | 113 | list($responseHeaders, $responseBody) = $this->parseHttpResponse($response, $headerSize); 114 | $responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); 115 | 116 | $this->client->getLogger()->debug( 117 | 'cURL response', 118 | array( 119 | 'code' => $responseCode, 120 | 'headers' => $responseHeaders, 121 | 'body' => $responseBody, 122 | ) 123 | ); 124 | 125 | return array($responseBody, $responseHeaders, $responseCode); 126 | } 127 | 128 | /** 129 | * Set options that update the transport implementation's behavior. 130 | * @param $options 131 | */ 132 | public function setOptions($options) 133 | { 134 | $this->options = $options + $this->options; 135 | } 136 | 137 | /** 138 | * Set the maximum request time in seconds. 139 | * @param $timeout in seconds 140 | */ 141 | public function setTimeout($timeout) 142 | { 143 | // Since this timeout is really for putting a bound on the time 144 | // we'll set them both to the same. If you need to specify a longer 145 | // CURLOPT_TIMEOUT, or a tigher CONNECTTIMEOUT, the best thing to 146 | // do is use the setOptions method for the values individually. 147 | $this->options[CURLOPT_CONNECTTIMEOUT] = $timeout; 148 | $this->options[CURLOPT_TIMEOUT] = $timeout; 149 | } 150 | 151 | /** 152 | * Get the maximum request time in seconds. 153 | * @return timeout in seconds 154 | */ 155 | public function getTimeout() 156 | { 157 | return $this->options[CURLOPT_TIMEOUT]; 158 | } 159 | 160 | /** 161 | * Test for the presence of a cURL header processing bug 162 | * 163 | * {@inheritDoc} 164 | * 165 | * @return boolean 166 | */ 167 | protected function needsQuirk() 168 | { 169 | $ver = curl_version(); 170 | $versionNum = $ver['version_number']; 171 | return $versionNum < Google_IO_Curl::NO_QUIRK_VERSION; 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/IO/Exception.php: -------------------------------------------------------------------------------- 1 | = 0) { 42 | parent::__construct($message, $code, $previous); 43 | } else { 44 | parent::__construct($message, $code); 45 | } 46 | 47 | if (is_array($retryMap)) { 48 | $this->retryMap = $retryMap; 49 | } 50 | } 51 | 52 | /** 53 | * Gets the number of times the associated task can be retried. 54 | * 55 | * NOTE: -1 is returned if the task can be retried indefinitely 56 | * 57 | * @return integer 58 | */ 59 | public function allowedRetries() 60 | { 61 | if (isset($this->retryMap[$this->code])) { 62 | return $this->retryMap[$this->code]; 63 | } 64 | 65 | return 0; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Logger/Exception.php: -------------------------------------------------------------------------------- 1 | getClassConfig('Google_Logger_File', 'file'); 57 | if (!is_string($file) && !is_resource($file)) { 58 | throw new Google_Logger_Exception( 59 | 'File logger requires a filename or a valid file pointer' 60 | ); 61 | } 62 | 63 | $mode = $client->getClassConfig('Google_Logger_File', 'mode'); 64 | if (!$mode) { 65 | $this->mode = $mode; 66 | } 67 | 68 | $this->lock = (bool) $client->getClassConfig('Google_Logger_File', 'lock'); 69 | $this->file = $file; 70 | } 71 | 72 | /** 73 | * {@inheritdoc} 74 | */ 75 | protected function write($message) 76 | { 77 | if (is_string($this->file)) { 78 | $this->open(); 79 | } elseif (!is_resource($this->file)) { 80 | throw new Google_Logger_Exception('File pointer is no longer available'); 81 | } 82 | 83 | if ($this->lock) { 84 | flock($this->file, LOCK_EX); 85 | } 86 | 87 | fwrite($this->file, (string) $message); 88 | 89 | if ($this->lock) { 90 | flock($this->file, LOCK_UN); 91 | } 92 | } 93 | 94 | /** 95 | * Opens the log for writing. 96 | * 97 | * @return resource 98 | */ 99 | private function open() 100 | { 101 | // Used for trapping `fopen()` errors. 102 | $this->trappedErrorNumber = null; 103 | $this->trappedErrorString = null; 104 | 105 | $old = set_error_handler(array($this, 'trapError')); 106 | 107 | $needsChmod = !file_exists($this->file); 108 | $fh = fopen($this->file, 'a'); 109 | 110 | restore_error_handler(); 111 | 112 | // Handles trapped `fopen()` errors. 113 | if ($this->trappedErrorNumber) { 114 | throw new Google_Logger_Exception( 115 | sprintf( 116 | "Logger Error: '%s'", 117 | $this->trappedErrorString 118 | ), 119 | $this->trappedErrorNumber 120 | ); 121 | } 122 | 123 | if ($needsChmod) { 124 | @chmod($this->file, $this->mode & ~umask()); 125 | } 126 | 127 | return $this->file = $fh; 128 | } 129 | 130 | /** 131 | * Closes the log stream resource. 132 | */ 133 | private function close() 134 | { 135 | if (is_resource($this->file)) { 136 | fclose($this->file); 137 | } 138 | } 139 | 140 | /** 141 | * Traps `fopen()` errors. 142 | * 143 | * @param integer $errno The error number 144 | * @param string $errstr The error string 145 | */ 146 | private function trapError($errno, $errstr) 147 | { 148 | $this->trappedErrorNumber = $errno; 149 | $this->trappedErrorString = $errstr; 150 | } 151 | 152 | public function __destruct() 153 | { 154 | $this->close(); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Logger/Null.php: -------------------------------------------------------------------------------- 1 | setLogger($logger); 43 | } 44 | } 45 | 46 | /** 47 | * Sets the PSR-3 logger where logging will be delegated. 48 | * 49 | * NOTE: The `$logger` should technically implement 50 | * `Psr\Log\LoggerInterface`, but we don't explicitly require this so that 51 | * we can be compatible with PHP 5.2. 52 | * 53 | * @param Psr\Log\LoggerInterface $logger The PSR-3 logger 54 | */ 55 | public function setLogger(/*Psr\Log\LoggerInterface*/ $logger) 56 | { 57 | $this->logger = $logger; 58 | } 59 | 60 | /** 61 | * {@inheritdoc} 62 | */ 63 | public function shouldHandle($level) 64 | { 65 | return isset($this->logger) && parent::shouldHandle($level); 66 | } 67 | 68 | /** 69 | * {@inheritdoc} 70 | */ 71 | public function log($level, $message, array $context = array()) 72 | { 73 | if (!$this->shouldHandle($level)) { 74 | return false; 75 | } 76 | 77 | if ($context) { 78 | $this->reverseJsonInContext($context); 79 | } 80 | 81 | $levelName = is_int($level) ? array_search($level, self::$levels) : $level; 82 | $this->logger->log($levelName, $message, $context); 83 | } 84 | 85 | /** 86 | * {@inheritdoc} 87 | */ 88 | protected function write($message, array $context = array()) 89 | { 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Service.php: -------------------------------------------------------------------------------- 1 | client = $client; 29 | } 30 | 31 | /** 32 | * Return the associated Google_Client class. 33 | * @return Google_Client 34 | */ 35 | public function getClient() 36 | { 37 | return $this->client; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Service/Admin.php: -------------------------------------------------------------------------------- 1 | 22 | * Email Migration API lets you migrate emails of users to Google backends.

23 | * 24 | *

25 | * For more information about this service, see the API 26 | * Documentation 27 | *

28 | * 29 | * @author Google, Inc. 30 | */ 31 | class Google_Service_Admin extends Google_Service 32 | { 33 | /** Manage email messages of users on your domain. */ 34 | const EMAIL_MIGRATION = 35 | "https://www.googleapis.com/auth/email.migration"; 36 | 37 | public $mail; 38 | 39 | 40 | /** 41 | * Constructs the internal representation of the Admin service. 42 | * 43 | * @param Google_Client $client 44 | */ 45 | public function __construct(Google_Client $client) 46 | { 47 | parent::__construct($client); 48 | $this->servicePath = 'email/v2/users/'; 49 | $this->version = 'email_migration_v2'; 50 | $this->serviceName = 'admin'; 51 | 52 | $this->mail = new Google_Service_Admin_Mail_Resource( 53 | $this, 54 | $this->serviceName, 55 | 'mail', 56 | array( 57 | 'methods' => array( 58 | 'insert' => array( 59 | 'path' => '{userKey}/mail', 60 | 'httpMethod' => 'POST', 61 | 'parameters' => array( 62 | 'userKey' => array( 63 | 'location' => 'path', 64 | 'type' => 'string', 65 | 'required' => true, 66 | ), 67 | ), 68 | ), 69 | ) 70 | ) 71 | ); 72 | } 73 | } 74 | 75 | 76 | /** 77 | * The "mail" collection of methods. 78 | * Typical usage is: 79 | * 80 | * $adminService = new Google_Service_Admin(...); 81 | * $mail = $adminService->mail; 82 | * 83 | */ 84 | class Google_Service_Admin_Mail_Resource extends Google_Service_Resource 85 | { 86 | 87 | /** 88 | * Insert Mail into Google's Gmail backends (mail.insert) 89 | * 90 | * @param string $userKey The email or immutable id of the user 91 | * @param Google_MailItem $postBody 92 | * @param array $optParams Optional parameters. 93 | */ 94 | public function insert($userKey, Google_Service_Admin_MailItem $postBody, $optParams = array()) 95 | { 96 | $params = array('userKey' => $userKey, 'postBody' => $postBody); 97 | $params = array_merge($params, $optParams); 98 | return $this->call('insert', array($params)); 99 | } 100 | } 101 | 102 | 103 | 104 | 105 | class Google_Service_Admin_MailItem extends Google_Collection 106 | { 107 | protected $collection_key = 'labels'; 108 | protected $internal_gapi_mappings = array( 109 | ); 110 | public $isDeleted; 111 | public $isDraft; 112 | public $isInbox; 113 | public $isSent; 114 | public $isStarred; 115 | public $isTrash; 116 | public $isUnread; 117 | public $kind; 118 | public $labels; 119 | 120 | 121 | public function setIsDeleted($isDeleted) 122 | { 123 | $this->isDeleted = $isDeleted; 124 | } 125 | public function getIsDeleted() 126 | { 127 | return $this->isDeleted; 128 | } 129 | public function setIsDraft($isDraft) 130 | { 131 | $this->isDraft = $isDraft; 132 | } 133 | public function getIsDraft() 134 | { 135 | return $this->isDraft; 136 | } 137 | public function setIsInbox($isInbox) 138 | { 139 | $this->isInbox = $isInbox; 140 | } 141 | public function getIsInbox() 142 | { 143 | return $this->isInbox; 144 | } 145 | public function setIsSent($isSent) 146 | { 147 | $this->isSent = $isSent; 148 | } 149 | public function getIsSent() 150 | { 151 | return $this->isSent; 152 | } 153 | public function setIsStarred($isStarred) 154 | { 155 | $this->isStarred = $isStarred; 156 | } 157 | public function getIsStarred() 158 | { 159 | return $this->isStarred; 160 | } 161 | public function setIsTrash($isTrash) 162 | { 163 | $this->isTrash = $isTrash; 164 | } 165 | public function getIsTrash() 166 | { 167 | return $this->isTrash; 168 | } 169 | public function setIsUnread($isUnread) 170 | { 171 | $this->isUnread = $isUnread; 172 | } 173 | public function getIsUnread() 174 | { 175 | return $this->isUnread; 176 | } 177 | public function setKind($kind) 178 | { 179 | $this->kind = $kind; 180 | } 181 | public function getKind() 182 | { 183 | return $this->kind; 184 | } 185 | public function setLabels($labels) 186 | { 187 | $this->labels = $labels; 188 | } 189 | public function getLabels() 190 | { 191 | return $this->labels; 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Service/Exception.php: -------------------------------------------------------------------------------- 1 | = 0) { 51 | parent::__construct($message, $code, $previous); 52 | } else { 53 | parent::__construct($message, $code); 54 | } 55 | 56 | $this->errors = $errors; 57 | 58 | if (is_array($retryMap)) { 59 | $this->retryMap = $retryMap; 60 | } 61 | } 62 | 63 | /** 64 | * An example of the possible errors returned. 65 | * 66 | * { 67 | * "domain": "global", 68 | * "reason": "authError", 69 | * "message": "Invalid Credentials", 70 | * "locationType": "header", 71 | * "location": "Authorization", 72 | * } 73 | * 74 | * @return [{string, string}] List of errors return in an HTTP response or []. 75 | */ 76 | public function getErrors() 77 | { 78 | return $this->errors; 79 | } 80 | 81 | /** 82 | * Gets the number of times the associated task can be retried. 83 | * 84 | * NOTE: -1 is returned if the task can be retried indefinitely 85 | * 86 | * @return integer 87 | */ 88 | public function allowedRetries() 89 | { 90 | if (isset($this->retryMap[$this->code])) { 91 | return $this->retryMap[$this->code]; 92 | } 93 | 94 | $errors = $this->getErrors(); 95 | 96 | if (!empty($errors) && isset($errors[0]['reason']) && 97 | isset($this->retryMap[$errors[0]['reason']])) { 98 | return $this->retryMap[$errors[0]['reason']]; 99 | } 100 | 101 | return 0; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Service/GroupsMigration.php: -------------------------------------------------------------------------------- 1 | 22 | * Groups Migration Api.

23 | * 24 | *

25 | * For more information about this service, see the API 26 | * Documentation 27 | *

28 | * 29 | * @author Google, Inc. 30 | */ 31 | class Google_Service_GroupsMigration extends Google_Service 32 | { 33 | 34 | 35 | public $archive; 36 | 37 | 38 | /** 39 | * Constructs the internal representation of the GroupsMigration service. 40 | * 41 | * @param Google_Client $client 42 | */ 43 | public function __construct(Google_Client $client) 44 | { 45 | parent::__construct($client); 46 | $this->servicePath = 'groups/v1/groups/'; 47 | $this->version = 'v1'; 48 | $this->serviceName = 'groupsmigration'; 49 | 50 | $this->archive = new Google_Service_GroupsMigration_Archive_Resource( 51 | $this, 52 | $this->serviceName, 53 | 'archive', 54 | array( 55 | 'methods' => array( 56 | 'insert' => array( 57 | 'path' => '{groupId}/archive', 58 | 'httpMethod' => 'POST', 59 | 'parameters' => array( 60 | 'groupId' => array( 61 | 'location' => 'path', 62 | 'type' => 'string', 63 | 'required' => true, 64 | ), 65 | ), 66 | ), 67 | ) 68 | ) 69 | ); 70 | } 71 | } 72 | 73 | 74 | /** 75 | * The "archive" collection of methods. 76 | * Typical usage is: 77 | * 78 | * $groupsmigrationService = new Google_Service_GroupsMigration(...); 79 | * $archive = $groupsmigrationService->archive; 80 | * 81 | */ 82 | class Google_Service_GroupsMigration_Archive_Resource extends Google_Service_Resource 83 | { 84 | 85 | /** 86 | * Inserts a new mail into the archive of the Google group. (archive.insert) 87 | * 88 | * @param string $groupId The group ID 89 | * @param array $optParams Optional parameters. 90 | * @return Google_Service_GroupsMigration_Groups 91 | */ 92 | public function insert($groupId, $optParams = array()) 93 | { 94 | $params = array('groupId' => $groupId); 95 | $params = array_merge($params, $optParams); 96 | return $this->call('insert', array($params), "Google_Service_GroupsMigration_Groups"); 97 | } 98 | } 99 | 100 | 101 | 102 | 103 | class Google_Service_GroupsMigration_Groups extends Google_Model 104 | { 105 | protected $internal_gapi_mappings = array( 106 | ); 107 | public $kind; 108 | public $responseCode; 109 | 110 | 111 | public function setKind($kind) 112 | { 113 | $this->kind = $kind; 114 | } 115 | public function getKind() 116 | { 117 | return $this->kind; 118 | } 119 | public function setResponseCode($responseCode) 120 | { 121 | $this->responseCode = $responseCode; 122 | } 123 | public function getResponseCode() 124 | { 125 | return $this->responseCode; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Service/Webfonts.php: -------------------------------------------------------------------------------- 1 | 22 | * The Google Fonts Developer API.

23 | * 24 | *

25 | * For more information about this service, see the API 26 | * Documentation 27 | *

28 | * 29 | * @author Google, Inc. 30 | */ 31 | class Google_Service_Webfonts extends Google_Service 32 | { 33 | 34 | 35 | public $webfonts; 36 | 37 | 38 | /** 39 | * Constructs the internal representation of the Webfonts service. 40 | * 41 | * @param Google_Client $client 42 | */ 43 | public function __construct(Google_Client $client) 44 | { 45 | parent::__construct($client); 46 | $this->servicePath = 'webfonts/v1/'; 47 | $this->version = 'v1'; 48 | $this->serviceName = 'webfonts'; 49 | 50 | $this->webfonts = new Google_Service_Webfonts_Webfonts_Resource( 51 | $this, 52 | $this->serviceName, 53 | 'webfonts', 54 | array( 55 | 'methods' => array( 56 | 'list' => array( 57 | 'path' => 'webfonts', 58 | 'httpMethod' => 'GET', 59 | 'parameters' => array( 60 | 'sort' => array( 61 | 'location' => 'query', 62 | 'type' => 'string', 63 | ), 64 | ), 65 | ), 66 | ) 67 | ) 68 | ); 69 | } 70 | } 71 | 72 | 73 | /** 74 | * The "webfonts" collection of methods. 75 | * Typical usage is: 76 | * 77 | * $webfontsService = new Google_Service_Webfonts(...); 78 | * $webfonts = $webfontsService->webfonts; 79 | * 80 | */ 81 | class Google_Service_Webfonts_Webfonts_Resource extends Google_Service_Resource 82 | { 83 | 84 | /** 85 | * Retrieves the list of fonts currently served by the Google Fonts Developer 86 | * API (webfonts.listWebfonts) 87 | * 88 | * @param array $optParams Optional parameters. 89 | * 90 | * @opt_param string sort Enables sorting of the list 91 | * @return Google_Service_Webfonts_WebfontList 92 | */ 93 | public function listWebfonts($optParams = array()) 94 | { 95 | $params = array(); 96 | $params = array_merge($params, $optParams); 97 | return $this->call('list', array($params), "Google_Service_Webfonts_WebfontList"); 98 | } 99 | } 100 | 101 | 102 | 103 | 104 | class Google_Service_Webfonts_Webfont extends Google_Collection 105 | { 106 | protected $collection_key = 'variants'; 107 | protected $internal_gapi_mappings = array( 108 | ); 109 | public $category; 110 | public $family; 111 | public $files; 112 | public $kind; 113 | public $lastModified; 114 | public $subsets; 115 | public $variants; 116 | public $version; 117 | 118 | 119 | public function setCategory($category) 120 | { 121 | $this->category = $category; 122 | } 123 | public function getCategory() 124 | { 125 | return $this->category; 126 | } 127 | public function setFamily($family) 128 | { 129 | $this->family = $family; 130 | } 131 | public function getFamily() 132 | { 133 | return $this->family; 134 | } 135 | public function setFiles($files) 136 | { 137 | $this->files = $files; 138 | } 139 | public function getFiles() 140 | { 141 | return $this->files; 142 | } 143 | public function setKind($kind) 144 | { 145 | $this->kind = $kind; 146 | } 147 | public function getKind() 148 | { 149 | return $this->kind; 150 | } 151 | public function setLastModified($lastModified) 152 | { 153 | $this->lastModified = $lastModified; 154 | } 155 | public function getLastModified() 156 | { 157 | return $this->lastModified; 158 | } 159 | public function setSubsets($subsets) 160 | { 161 | $this->subsets = $subsets; 162 | } 163 | public function getSubsets() 164 | { 165 | return $this->subsets; 166 | } 167 | public function setVariants($variants) 168 | { 169 | $this->variants = $variants; 170 | } 171 | public function getVariants() 172 | { 173 | return $this->variants; 174 | } 175 | public function setVersion($version) 176 | { 177 | $this->version = $version; 178 | } 179 | public function getVersion() 180 | { 181 | return $this->version; 182 | } 183 | } 184 | 185 | class Google_Service_Webfonts_WebfontFiles extends Google_Model 186 | { 187 | } 188 | 189 | class Google_Service_Webfonts_WebfontList extends Google_Collection 190 | { 191 | protected $collection_key = 'items'; 192 | protected $internal_gapi_mappings = array( 193 | ); 194 | protected $itemsType = 'Google_Service_Webfonts_Webfont'; 195 | protected $itemsDataType = 'array'; 196 | public $kind; 197 | 198 | 199 | public function setItems($items) 200 | { 201 | $this->items = $items; 202 | } 203 | public function getItems() 204 | { 205 | return $this->items; 206 | } 207 | public function setKind($kind) 208 | { 209 | $this->kind = $kind; 210 | } 211 | public function getKind() 212 | { 213 | return $this->kind; 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Signer/Abstract.php: -------------------------------------------------------------------------------- 1 | 22 | */ 23 | abstract class Google_Signer_Abstract 24 | { 25 | /** 26 | * Signs data, returns the signature as binary data. 27 | */ 28 | abstract public function sign($data); 29 | } 30 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Signer/P12.php: -------------------------------------------------------------------------------- 1 | 26 | */ 27 | class Google_Signer_P12 extends Google_Signer_Abstract 28 | { 29 | // OpenSSL private key resource 30 | private $privateKey; 31 | 32 | // Creates a new signer from a .p12 file. 33 | public function __construct($p12, $password) 34 | { 35 | if (!function_exists('openssl_x509_read')) { 36 | throw new Google_Exception( 37 | 'The Google PHP API library needs the openssl PHP extension' 38 | ); 39 | } 40 | 41 | // If the private key is provided directly, then this isn't in the p12 42 | // format. Different versions of openssl support different p12 formats 43 | // and the key from google wasn't being accepted by the version available 44 | // at the time. 45 | if (!$password && strpos($p12, "-----BEGIN RSA PRIVATE KEY-----") !== false) { 46 | $this->privateKey = openssl_pkey_get_private($p12); 47 | } else { 48 | // This throws on error 49 | $certs = array(); 50 | if (!openssl_pkcs12_read($p12, $certs, $password)) { 51 | throw new Google_Auth_Exception( 52 | "Unable to parse the p12 file. " . 53 | "Is this a .p12 file? Is the password correct? OpenSSL error: " . 54 | openssl_error_string() 55 | ); 56 | } 57 | // TODO(beaton): is this part of the contract for the openssl_pkcs12_read 58 | // method? What happens if there are multiple private keys? Do we care? 59 | if (!array_key_exists("pkey", $certs) || !$certs["pkey"]) { 60 | throw new Google_Auth_Exception("No private key found in p12 file."); 61 | } 62 | $this->privateKey = openssl_pkey_get_private($certs['pkey']); 63 | } 64 | 65 | if (!$this->privateKey) { 66 | throw new Google_Auth_Exception("Unable to load private key"); 67 | } 68 | } 69 | 70 | public function __destruct() 71 | { 72 | if ($this->privateKey) { 73 | openssl_pkey_free($this->privateKey); 74 | } 75 | } 76 | 77 | public function sign($data) 78 | { 79 | if (version_compare(PHP_VERSION, '5.3.0') < 0) { 80 | throw new Google_Auth_Exception( 81 | "PHP 5.3.0 or higher is required to use service accounts." 82 | ); 83 | } 84 | $hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256"; 85 | if (!openssl_sign($data, $signature, $this->privateKey, $hash)) { 86 | throw new Google_Auth_Exception("Unable to sign data"); 87 | } 88 | return $signature; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Task/Exception.php: -------------------------------------------------------------------------------- 1 | 23 | */ 24 | class Google_Utils 25 | { 26 | public static function urlSafeB64Encode($data) 27 | { 28 | $b64 = base64_encode($data); 29 | $b64 = str_replace( 30 | array('+', '/', '\r', '\n', '='), 31 | array('-', '_'), 32 | $b64 33 | ); 34 | return $b64; 35 | } 36 | 37 | public static function urlSafeB64Decode($b64) 38 | { 39 | $b64 = str_replace( 40 | array('-', '_'), 41 | array('+', '/'), 42 | $b64 43 | ); 44 | return base64_decode($b64); 45 | } 46 | 47 | /** 48 | * Misc function used to count the number of bytes in a post body, in the 49 | * world of multi-byte chars and the unpredictability of 50 | * strlen/mb_strlen/sizeof, this is the only way to do that in a sane 51 | * manner at the moment. 52 | * 53 | * This algorithm was originally developed for the 54 | * Solar Framework by Paul M. Jones 55 | * 56 | * @link http://solarphp.com/ 57 | * @link http://svn.solarphp.com/core/trunk/Solar/Json.php 58 | * @link http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Json/Decoder.php 59 | * @param string $str 60 | * @return int The number of bytes in a string. 61 | */ 62 | public static function getStrLen($str) 63 | { 64 | $strlenVar = strlen($str); 65 | $d = $ret = 0; 66 | for ($count = 0; $count < $strlenVar; ++ $count) { 67 | $ordinalValue = ord($str{$ret}); 68 | switch (true) { 69 | case (($ordinalValue >= 0x20) && ($ordinalValue <= 0x7F)): 70 | // characters U-00000000 - U-0000007F (same as ASCII) 71 | $ret ++; 72 | break; 73 | case (($ordinalValue & 0xE0) == 0xC0): 74 | // characters U-00000080 - U-000007FF, mask 110XXXXX 75 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 76 | $ret += 2; 77 | break; 78 | case (($ordinalValue & 0xF0) == 0xE0): 79 | // characters U-00000800 - U-0000FFFF, mask 1110XXXX 80 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 81 | $ret += 3; 82 | break; 83 | case (($ordinalValue & 0xF8) == 0xF0): 84 | // characters U-00010000 - U-001FFFFF, mask 11110XXX 85 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 86 | $ret += 4; 87 | break; 88 | case (($ordinalValue & 0xFC) == 0xF8): 89 | // characters U-00200000 - U-03FFFFFF, mask 111110XX 90 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 91 | $ret += 5; 92 | break; 93 | case (($ordinalValue & 0xFE) == 0xFC): 94 | // characters U-04000000 - U-7FFFFFFF, mask 1111110X 95 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 96 | $ret += 6; 97 | break; 98 | default: 99 | $ret ++; 100 | } 101 | } 102 | return $ret; 103 | } 104 | 105 | /** 106 | * Normalize all keys in an array to lower-case. 107 | * @param array $arr 108 | * @return array Normalized array. 109 | */ 110 | public static function normalize($arr) 111 | { 112 | if (!is_array($arr)) { 113 | return array(); 114 | } 115 | 116 | $normalized = array(); 117 | foreach ($arr as $key => $val) { 118 | $normalized[strtolower($key)] = $val; 119 | } 120 | return $normalized; 121 | } 122 | 123 | /** 124 | * Convert a string to camelCase 125 | * @param string $value 126 | * @return string 127 | */ 128 | public static function camelCase($value) 129 | { 130 | $value = ucwords(str_replace(array('-', '_'), ' ', $value)); 131 | $value = str_replace(' ', '', $value); 132 | $value[0] = strtolower($value[0]); 133 | return $value; 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Verifier/Abstract.php: -------------------------------------------------------------------------------- 1 | 22 | */ 23 | abstract class Google_Verifier_Abstract 24 | { 25 | /** 26 | * Checks a signature, returns true if the signature is correct, 27 | * false otherwise. 28 | */ 29 | abstract public function verify($data, $signature); 30 | } 31 | -------------------------------------------------------------------------------- /google-api-php-client/src/Google/Verifier/Pem.php: -------------------------------------------------------------------------------- 1 | 24 | */ 25 | class Google_Verifier_Pem extends Google_Verifier_Abstract 26 | { 27 | private $publicKey; 28 | 29 | /** 30 | * Constructs a verifier from the supplied PEM-encoded certificate. 31 | * 32 | * $pem: a PEM encoded certificate (not a file). 33 | * @param $pem 34 | * @throws Google_Auth_Exception 35 | * @throws Google_Exception 36 | */ 37 | public function __construct($pem) 38 | { 39 | if (!function_exists('openssl_x509_read')) { 40 | throw new Google_Exception('Google API PHP client needs the openssl PHP extension'); 41 | } 42 | $this->publicKey = openssl_x509_read($pem); 43 | if (!$this->publicKey) { 44 | throw new Google_Auth_Exception("Unable to parse PEM: $pem"); 45 | } 46 | } 47 | 48 | public function __destruct() 49 | { 50 | if ($this->publicKey) { 51 | openssl_x509_free($this->publicKey); 52 | } 53 | } 54 | 55 | /** 56 | * Verifies the signature on data. 57 | * 58 | * Returns true if the signature is valid, false otherwise. 59 | * @param $data 60 | * @param $signature 61 | * @throws Google_Auth_Exception 62 | * @return bool 63 | */ 64 | public function verify($data, $signature) 65 | { 66 | $hash = defined("OPENSSL_ALGO_SHA256") ? OPENSSL_ALGO_SHA256 : "sha256"; 67 | $status = openssl_verify($data, $signature, $this->publicKey, $hash); 68 | if ($status === -1) { 69 | throw new Google_Auth_Exception('Signature verification error: ' . openssl_error_string()); 70 | } 71 | return $status === 1; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /google-api-php-client/tests/BaseTest.php: -------------------------------------------------------------------------------- 1 | token = ''; 31 | 32 | $this->memcacheHost = getenv('MEMCACHE_HOST') ? getenv('MEMCACHE_HOST') : null; 33 | $this->memcachePort = getenv('MEMCACHE_PORT') ? getenv('MEMCACHE_PORT') : null; 34 | } 35 | 36 | public function getClient() 37 | { 38 | $client = new Google_Client(); 39 | $client->setDeveloperKey(self::KEY); 40 | if (strlen($this->token)) { 41 | $client->setAccessToken($this->token); 42 | } 43 | if (strlen($this->memcacheHost)) { 44 | $client->setClassConfig('Google_Cache_Memcache', 'host', $this->memcacheHost); 45 | $client->setClassConfig('Google_Cache_Memcache', 'port', $this->memcachePort); 46 | } 47 | return $client; 48 | } 49 | 50 | public function checkToken() 51 | { 52 | if (!strlen($this->token)) { 53 | $this->markTestSkipped('Test requires access token'); 54 | return false; 55 | } 56 | return true; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /google-api-php-client/tests/OAuthHelper.php: -------------------------------------------------------------------------------- 1 | setScopes( 21 | array( 22 | "https://www.googleapis.com/auth/plus.me", 23 | "https://www.googleapis.com/auth/urlshortener", 24 | "https://www.googleapis.com/auth/tasks", 25 | "https://www.googleapis.com/auth/adsense", 26 | "https://www.googleapis.com/auth/youtube" 27 | ) 28 | ); 29 | $client->setRedirectUri("urn:ietf:wg:oauth:2.0:oob"); 30 | // Visit https://code.google.com/apis/console to 31 | // generate your oauth2_client_id, oauth2_client_secret, and to 32 | // register your oauth2_redirect_uri. 33 | $client->setClientId(""); 34 | $client->setClientSecret(""); 35 | 36 | $authUrl = $client->createAuthUrl(); 37 | 38 | `open '$authUrl'`; 39 | echo "\nPlease enter the auth code:\n"; 40 | $authCode = trim(fgets(STDIN)); 41 | 42 | $accessToken = $client->authenticate($authCode); 43 | 44 | echo "\n", 'Add the following to BaseTest.php as the $token value:', "\n\n"; 45 | echo $accessToken, "\n\n"; 46 | -------------------------------------------------------------------------------- /google-api-php-client/tests/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/tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | checkToken()) { 28 | return; 29 | } 30 | $client = $this->getClient(); 31 | $batch = new Google_Http_Batch($client); 32 | $this->plus = new Google_Service_Plus($client); 33 | 34 | $client->setUseBatch(true); 35 | $batch->add($this->plus->people->get('me'), 'key1'); 36 | $batch->add($this->plus->people->get('me'), 'key2'); 37 | $batch->add($this->plus->people->get('me'), 'key3'); 38 | 39 | $result = $batch->execute(); 40 | $this->assertTrue(isset($result['response-key1'])); 41 | $this->assertTrue(isset($result['response-key2'])); 42 | $this->assertTrue(isset($result['response-key3'])); 43 | } 44 | 45 | public function testBatchRequest() 46 | { 47 | $client = $this->getClient(); 48 | $batch = new Google_Http_Batch($client); 49 | $this->plus = new Google_Service_Plus($client); 50 | 51 | $client->setUseBatch(true); 52 | $batch->add($this->plus->people->get('+LarryPage'), 'key1'); 53 | $batch->add($this->plus->people->get('+LarryPage'), 'key2'); 54 | $batch->add($this->plus->people->get('+LarryPage'), 'key3'); 55 | 56 | $result = $batch->execute(); 57 | $this->assertTrue(isset($result['response-key1'])); 58 | $this->assertTrue(isset($result['response-key2'])); 59 | $this->assertTrue(isset($result['response-key3'])); 60 | } 61 | 62 | public function testInvalidBatchRequest() 63 | { 64 | $client = $this->getClient(); 65 | $batch = new Google_Http_Batch($client); 66 | $this->plus = new Google_Service_Plus($client); 67 | 68 | $client->setUseBatch(true); 69 | $batch->add($this->plus->people->get('123456789987654321'), 'key1'); 70 | $batch->add($this->plus->people->get('+LarryPage'), 'key2'); 71 | 72 | $result = $batch->execute(); 73 | $this->assertTrue(isset($result['response-key2'])); 74 | $this->assertInstanceOf( 75 | 'Google_Service_Exception', 76 | $result['response-key1'] 77 | ); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /google-api-php-client/tests/general/ApiMediaFileUploadTest.php: -------------------------------------------------------------------------------- 1 | getClient(); 26 | $request = new Google_Http_Request('http://www.example.com', 'POST'); 27 | $media = new Google_Http_MediaFileUpload( 28 | $client, 29 | $request, 30 | 'image/png', 31 | base64_decode('data:image/png;base64,a') 32 | ); 33 | 34 | $this->assertEquals(0, $media->getProgress()); 35 | $this->assertGreaterThan(0, strlen($request->getPostBody())); 36 | } 37 | 38 | public function testGetUploadType() 39 | { 40 | $client = $this->getClient(); 41 | $request = new Google_Http_Request('http://www.example.com', 'POST'); 42 | 43 | // Test resumable upload 44 | $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', 'a', true); 45 | $params = array('mediaUpload' => array('value' => $media)); 46 | $this->assertEquals('resumable', $media->getUploadType(null)); 47 | 48 | // Test data *only* uploads 49 | $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', 'a', false); 50 | $this->assertEquals('media', $media->getUploadType(null)); 51 | 52 | // Test multipart uploads 53 | $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', 'a', false); 54 | $this->assertEquals('multipart', $media->getUploadType(array('a' => 'b'))); 55 | } 56 | 57 | public function testResultCode() 58 | { 59 | $client = $this->getClient(); 60 | $request = new Google_Http_Request('http://www.example.com', 'POST'); 61 | 62 | // Test resumable upload 63 | $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', 'a', true); 64 | $this->assertEquals(null, $media->getHttpResultCode()); 65 | } 66 | 67 | public function testProcess() 68 | { 69 | $client = $this->getClient(); 70 | $data = 'foo'; 71 | 72 | // Test data *only* uploads. 73 | $request = new Google_Http_Request('http://www.example.com', 'POST'); 74 | $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, false); 75 | $this->assertEquals($data, $request->getPostBody()); 76 | 77 | // Test resumable (meta data) - we want to send the metadata, not the app data. 78 | $request = new Google_Http_Request('http://www.example.com', 'POST'); 79 | $reqData = json_encode("hello"); 80 | $request->setPostBody($reqData); 81 | $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, true); 82 | $this->assertEquals(json_decode($reqData), $request->getPostBody()); 83 | 84 | // Test multipart - we are sending encoded meta data and post data 85 | $request = new Google_Http_Request('http://www.example.com', 'POST'); 86 | $reqData = json_encode("hello"); 87 | $request->setPostBody($reqData); 88 | $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, false); 89 | $this->assertContains($reqData, $request->getPostBody()); 90 | $this->assertContains(base64_encode($data), $request->getPostBody()); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /google-api-php-client/tests/general/ApiModelTest.php: -------------------------------------------------------------------------------- 1 | setDate($dateString); 68 | $event->setStart($date); 69 | $event->setEnd($date); 70 | $event->setSummary($summary); 71 | $simpleEvent = $event->toSimpleObject(); 72 | $this->assertEquals($dateString, $simpleEvent->start->date); 73 | $this->assertEquals($dateString, $simpleEvent->end->date); 74 | $this->assertEquals($summary, $simpleEvent->summary); 75 | 76 | $event2 = new Google_Service_Calendar_Event(); 77 | $this->assertNull($event2->getStart()); 78 | } 79 | 80 | public function testVariantTypes() 81 | { 82 | $feature = new Google_Service_MapsEngine_Feature(); 83 | $geometry = new Google_Service_MapsEngine_GeoJsonPoint(); 84 | $geometry->setCoordinates(array(1, 0)); 85 | $feature->setGeometry($geometry); 86 | $data = json_decode(json_encode($feature->toSimpleObject()), true); 87 | $this->assertEquals('Point', $data['geometry']['type']); 88 | $this->assertEquals(1, $data['geometry']['coordinates'][0]); 89 | } 90 | 91 | public function testOddMappingNames() 92 | { 93 | $creative = new Google_Service_AdExchangeBuyer_Creative(); 94 | $creative->setAccountId('12345'); 95 | $creative->setBuyerCreativeId('12345'); 96 | $creative->setAdvertiserName('Hi'); 97 | $creative->setHTMLSnippet("

Foo!

"); 98 | $creative->setClickThroughUrl(array('http://somedomain.com')); 99 | $creative->setWidth(100); 100 | $creative->setHeight(100); 101 | $data = json_decode(json_encode($creative->toSimpleObject()), true); 102 | $this->assertEquals($data['HTMLSnippet'], "

Foo!

"); 103 | $this->assertEquals($data['width'], 100); 104 | $this->assertEquals($data['height'], 100); 105 | $this->assertEquals($data['accountId'], "12345"); 106 | } 107 | 108 | public function testJsonStructure() 109 | { 110 | $model = new Google_Model(); 111 | $model->publicA = "This is a string"; 112 | $model2 = new Google_Model(); 113 | $model2->publicC = 12345; 114 | $model2->publicD = null; 115 | $model->publicB = $model2; 116 | $model3 = new Google_Model(); 117 | $model3->publicE = 54321; 118 | $model3->publicF = null; 119 | $model->publicG = array($model3, "hello", false); 120 | $model->publicH = false; 121 | $model->publicI = 0; 122 | $string = json_encode($model->toSimpleObject()); 123 | $data = json_decode($string, true); 124 | $this->assertEquals(12345, $data['publicB']['publicC']); 125 | $this->assertEquals("This is a string", $data['publicA']); 126 | $this->assertArrayNotHasKey("publicD", $data['publicB']); 127 | $this->assertArrayHasKey("publicE", $data['publicG'][0]); 128 | $this->assertArrayNotHasKey("publicF", $data['publicG'][0]); 129 | $this->assertEquals("hello", $data['publicG'][1]); 130 | $this->assertEquals(false, $data['publicG'][2]); 131 | $this->assertArrayNotHasKey("data", $data); 132 | $this->assertEquals(false, $data['publicH']); 133 | $this->assertEquals(0, $data['publicI']); 134 | } 135 | 136 | public function testIssetPropertyOnModel() 137 | { 138 | $model = new Google_Model(); 139 | $model['foo'] = 'bar'; 140 | $this->assertTrue(isset($model->foo)); 141 | } 142 | 143 | public function testUnsetPropertyOnModel() 144 | { 145 | $model = new Google_Model(); 146 | $model['foo'] = 'bar'; 147 | unset($model->foo); 148 | $this->assertFalse(isset($model->foo)); 149 | } 150 | 151 | public function testCollection() 152 | { 153 | $data = json_decode( 154 | '{ 155 | "kind": "calendar#events", 156 | "id": "1234566", 157 | "etag": "abcdef", 158 | "totalItems": 4, 159 | "items": [ 160 | {"id": 1}, 161 | {"id": 2}, 162 | {"id": 3}, 163 | {"id": 4} 164 | ] 165 | }', 166 | true 167 | ); 168 | $collection = new Google_Service_Calendar_Events($data); 169 | $this->assertEquals(4, count($collection)); 170 | $count = 0; 171 | foreach ($collection as $col) { 172 | $count++; 173 | } 174 | $this->assertEquals(4, $count); 175 | $this->assertEquals(1, $collection[0]->id); 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /google-api-php-client/tests/general/CacheTest.php: -------------------------------------------------------------------------------- 1 | getClient(); 27 | $client->setClassConfig( 28 | 'Google_Cache_File', 29 | 'directory', 30 | $dir 31 | ); 32 | $cache = new Google_Cache_File($client); 33 | $cache->set('foo', 'bar'); 34 | $this->assertEquals($cache->get('foo'), 'bar'); 35 | 36 | $this->getSetDelete($cache); 37 | } 38 | 39 | /** 40 | * @requires extension Memcache 41 | */ 42 | public function testNull() 43 | { 44 | $client = $this->getClient(); 45 | $cache = new Google_Cache_Null($client); 46 | $client->setCache($cache); 47 | 48 | $cache->set('foo', 'bar'); 49 | $cache->delete('foo'); 50 | $this->assertEquals(false, $cache->get('foo')); 51 | 52 | $cache->set('foo.1', 'bar.1'); 53 | $this->assertEquals($cache->get('foo.1'), false); 54 | 55 | $cache->set('foo', 'baz'); 56 | $this->assertEquals($cache->get('foo'), false); 57 | 58 | $cache->set('foo', null); 59 | $cache->delete('foo'); 60 | $this->assertEquals($cache->get('foo'), false); 61 | } 62 | 63 | /** 64 | * @requires extension Memcache 65 | */ 66 | public function testMemcache() 67 | { 68 | $client = $this->getClient(); 69 | if (!$client->getClassConfig('Google_Cache_Memcache', 'host')) { 70 | $this->markTestSkipped('Test requires memcache host specified'); 71 | } 72 | 73 | $cache = new Google_Cache_Memcache($client); 74 | 75 | $this->getSetDelete($cache); 76 | } 77 | 78 | /** 79 | * @requires extension APC 80 | */ 81 | public function testAPC() 82 | { 83 | if (!ini_get('apc.enable_cli')) { 84 | $this->markTestSkipped('Test requires APC enabled for CLI'); 85 | } 86 | $client = $this->getClient(); 87 | $cache = new Google_Cache_Apc($client); 88 | 89 | $this->getSetDelete($cache); 90 | } 91 | 92 | public function getSetDelete($cache) 93 | { 94 | $cache->set('foo', 'bar'); 95 | $cache->delete('foo'); 96 | $this->assertEquals(false, $cache->get('foo')); 97 | 98 | $cache->set('foo.1', 'bar.1'); 99 | $cache->delete('foo.1'); 100 | $this->assertEquals($cache->get('foo.1'), false); 101 | 102 | $cache->set('foo', 'baz'); 103 | $cache->delete('foo'); 104 | $this->assertEquals($cache->get('foo'), false); 105 | 106 | $cache->set('foo', null); 107 | $cache->delete('foo'); 108 | $this->assertEquals($cache->get('foo'), false); 109 | 110 | $obj = new stdClass(); 111 | $obj->foo = 'bar'; 112 | $cache->set('foo', $obj); 113 | $cache->delete('foo'); 114 | $this->assertEquals($cache->get('foo'), false); 115 | 116 | $cache->set('foo.1', 'bar.1'); 117 | $this->assertEquals($cache->get('foo.1'), 'bar.1'); 118 | 119 | $cache->set('foo', 'baz'); 120 | $this->assertEquals($cache->get('foo'), 'baz'); 121 | 122 | $cache->set('foo', null); 123 | $this->assertEquals($cache->get('foo'), null); 124 | 125 | $cache->set('1/2/3', 'bar'); 126 | $this->assertEquals($cache->get('1/2/3'), 'bar'); 127 | 128 | $obj = new stdClass(); 129 | $obj->foo = 'bar'; 130 | $cache->set('foo', $obj); 131 | $this->assertEquals($cache->get('foo'), $obj); 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /google-api-php-client/tests/general/RequestTest.php: -------------------------------------------------------------------------------- 1 | setExpectedClass("Google_Client"); 29 | $this->assertEquals(2, count($request->getQueryParams())); 30 | $request->setQueryParam("hi", "there"); 31 | $this->assertEquals($url2, $request->getUrl()); 32 | $this->assertEquals("Google_Client", $request->getExpectedClass()); 33 | 34 | $urlPath = "/foo/bar"; 35 | $request = new Google_Http_Request($urlPath); 36 | $this->assertEquals($urlPath, $request->getUrl()); 37 | $request->setBaseComponent("http://example.com"); 38 | $this->assertEquals("http://example.com" . $urlPath, $request->getUrl()); 39 | 40 | $url3a = 'http://localhost:8080/foo/bar'; 41 | $url3b = 'foo=a&foo=b&wowee=oh+my'; 42 | $url3c = 'foo=a&foo=b&wowee=oh+my&hi=there'; 43 | $request = new Google_Http_Request($url3a."?".$url3b, "POST"); 44 | $request->setQueryParam("hi", "there"); 45 | $request->maybeMoveParametersToBody(); 46 | $this->assertEquals($url3a, $request->getUrl()); 47 | $this->assertEquals($url3c, $request->getPostBody()); 48 | 49 | $url4 = 'http://localhost:8080/upload/foo/bar?foo=a&foo=b&wowee=oh+my&hi=there'; 50 | $request = new Google_Http_Request($url); 51 | $this->assertEquals(2, count($request->getQueryParams())); 52 | $request->setQueryParam("hi", "there"); 53 | $base = $request->getBaseComponent(); 54 | $request->setBaseComponent($base . '/upload'); 55 | $this->assertEquals($url4, $request->getUrl()); 56 | } 57 | 58 | public function testGzipSupport() 59 | { 60 | $url = 'http://localhost:8080/foo/bar?foo=a&foo=b&wowee=oh+my'; 61 | $request = new Google_Http_Request($url); 62 | $request->enableGzip(); 63 | $this->assertStringEndsWith(Google_Http_Request::GZIP_UA, $request->getUserAgent()); 64 | $this->assertArrayHasKey('accept-encoding', $request->getRequestHeaders()); 65 | $this->assertTrue($request->canGzip()); 66 | $request->disableGzip(); 67 | $this->assertStringEndsNotWith(Google_Http_Request::GZIP_UA, $request->getUserAgent()); 68 | $this->assertArrayNotHasKey('accept-encoding', $request->getRequestHeaders()); 69 | $this->assertFalse($request->canGzip()); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /google-api-php-client/tests/general/RestTest.php: -------------------------------------------------------------------------------- 1 | rest = new Google_Http_REST(); 28 | } 29 | 30 | public function testDecodeResponse() 31 | { 32 | $url = 'http://localhost'; 33 | $client = $this->getClient(); 34 | $response = new Google_Http_Request($url); 35 | $response->setResponseHttpCode(204); 36 | $decoded = $this->rest->decodeHttpResponse($response, $client); 37 | $this->assertEquals(null, $decoded); 38 | 39 | 40 | foreach (array(200, 201) as $code) { 41 | $headers = array('foo', 'bar'); 42 | $response = new Google_Http_Request($url, 'GET', $headers); 43 | $response->setResponseBody('{"a": 1}'); 44 | 45 | $response->setResponseHttpCode($code); 46 | $decoded = $this->rest->decodeHttpResponse($response, $client); 47 | $this->assertEquals(array("a" => 1), $decoded); 48 | } 49 | 50 | $response = new Google_Http_Request($url); 51 | $response->setResponseHttpCode(500); 52 | 53 | $error = ""; 54 | try { 55 | $this->rest->decodeHttpResponse($response, $client); 56 | } catch (Exception $e) { 57 | $error = $e->getMessage(); 58 | 59 | } 60 | $this->assertEquals(trim($error), "Error calling GET http://localhost: (500)"); 61 | } 62 | 63 | 64 | public function testDecodeEmptyResponse() 65 | { 66 | $url = 'http://localhost'; 67 | 68 | $response = new Google_Http_Request($url, 'GET', array()); 69 | $response->setResponseBody('{}'); 70 | 71 | $response->setResponseHttpCode(200); 72 | $decoded = $this->rest->decodeHttpResponse($response); 73 | $this->assertEquals(array(), $decoded); 74 | } 75 | 76 | public function testCreateRequestUri() 77 | { 78 | $basePath = "http://localhost"; 79 | $restPath = "/plus/{u}"; 80 | 81 | // Test Path 82 | $params = array(); 83 | $params['u']['type'] = 'string'; 84 | $params['u']['location'] = 'path'; 85 | $params['u']['value'] = 'me'; 86 | $value = $this->rest->createRequestUri($basePath, $restPath, $params); 87 | $this->assertEquals("http://localhost/plus/me", $value); 88 | 89 | // Test Query 90 | $params = array(); 91 | $params['u']['type'] = 'string'; 92 | $params['u']['location'] = 'query'; 93 | $params['u']['value'] = 'me'; 94 | $value = $this->rest->createRequestUri($basePath, '/plus', $params); 95 | $this->assertEquals("http://localhost/plus?u=me", $value); 96 | 97 | // Test Booleans 98 | $params = array(); 99 | $params['u']['type'] = 'boolean'; 100 | $params['u']['location'] = 'path'; 101 | $params['u']['value'] = '1'; 102 | $value = $this->rest->createRequestUri($basePath, $restPath, $params); 103 | $this->assertEquals("http://localhost/plus/true", $value); 104 | 105 | $params['u']['location'] = 'query'; 106 | $value = $this->rest->createRequestUri($basePath, '/plus', $params); 107 | $this->assertEquals("http://localhost/plus?u=true", $value); 108 | 109 | // Test encoding 110 | $params = array(); 111 | $params['u']['type'] = 'string'; 112 | $params['u']['location'] = 'query'; 113 | $params['u']['value'] = '@me/'; 114 | $value = $this->rest->createRequestUri($basePath, '/plus', $params); 115 | $this->assertEquals("http://localhost/plus?u=%40me%2F", $value); 116 | } 117 | 118 | /** 119 | * @expectedException Google_Service_Exception 120 | */ 121 | public function testBadErrorFormatting() 122 | { 123 | $request = new Google_Http_Request("/a/b"); 124 | $request->setResponseHttpCode(500); 125 | $request->setResponseBody( 126 | '{ 127 | "error": { 128 | "code": 500, 129 | "message": null 130 | } 131 | }' 132 | ); 133 | Google_Http_Rest::decodeHttpResponse($request); 134 | } 135 | 136 | /** 137 | * @expectedException Google_Service_Exception 138 | */ 139 | public function tesProperErrorFormatting() 140 | { 141 | $request = new Google_Http_Request("/a/b"); 142 | $request->setResponseHttpCode(401); 143 | $request->setResponseBody( 144 | '{ 145 | error: { 146 | errors: [ 147 | { 148 | "domain": "global", 149 | "reason": "authError", 150 | "message": "Invalid Credentials", 151 | "locationType": "header", 152 | "location": "Authorization", 153 | } 154 | ], 155 | "code": 401, 156 | "message": "Invalid Credentials" 157 | }' 158 | ); 159 | Google_Http_Rest::decodeHttpResponse($request); 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /google-api-php-client/tests/general/ServiceTest.php: -------------------------------------------------------------------------------- 1 | mapTypes( 41 | array( 42 | 'name' => 'asdf', 43 | 'gender' => 'z', 44 | ) 45 | ); 46 | $this->assertEquals('asdf', $model->name); 47 | $this->assertEquals('z', $model->gender); 48 | $model->mapTypes( 49 | array( 50 | '__infoType' => 'Google_Model', 51 | '__infoDataType' => 'map', 52 | 'info' => array ( 53 | 'location' => 'mars', 54 | 'timezone' => 'mst', 55 | ), 56 | 'name' => 'asdf', 57 | 'gender' => 'z', 58 | ) 59 | ); 60 | $this->assertEquals('asdf', $model->name); 61 | $this->assertEquals('z', $model->gender); 62 | 63 | $this->assertEquals(false, $model->isAssociativeArray("")); 64 | $this->assertEquals(false, $model->isAssociativeArray(false)); 65 | $this->assertEquals(false, $model->isAssociativeArray(null)); 66 | $this->assertEquals(false, $model->isAssociativeArray(array())); 67 | $this->assertEquals(false, $model->isAssociativeArray(array(1, 2))); 68 | $this->assertEquals(false, $model->isAssociativeArray(array(1 => 2))); 69 | 70 | $this->assertEquals(true, $model->isAssociativeArray(array('test' => 'a'))); 71 | $this->assertEquals(true, $model->isAssociativeArray(array("a", "b" => 2))); 72 | } 73 | 74 | /** 75 | * @dataProvider serviceProvider 76 | */ 77 | public function testIncludes($class) 78 | { 79 | $this->assertTrue( 80 | class_exists($class), 81 | sprintf('Failed asserting class %s exists.', $class) 82 | ); 83 | } 84 | 85 | public function serviceProvider() 86 | { 87 | $classes = array(); 88 | $path = dirname(dirname(dirname(__FILE__))) . '/src/Google/Service'; 89 | foreach (glob($path . "/*.php") as $file) { 90 | $classes[] = array('Google_Service_' . basename($file, '.php')); 91 | } 92 | 93 | return $classes; 94 | } 95 | 96 | public function testStrLen() 97 | { 98 | $this->assertEquals(0, Google_Utils::getStrLen(null)); 99 | $this->assertEquals(0, Google_Utils::getStrLen(false)); 100 | $this->assertEquals(0, Google_Utils::getStrLen("")); 101 | 102 | $this->assertEquals(1, Google_Utils::getStrLen(" ")); 103 | $this->assertEquals(2, Google_Utils::getStrLen(" 1")); 104 | $this->assertEquals(7, Google_Utils::getStrLen("0a\\n\n\r\n")); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /google-api-php-client/tests/general/testdata/cacert.json: -------------------------------------------------------------------------------- 1 | {"a": "-----BEGIN CERTIFICATE-----\nMIICrDCCAlagAwIBAgIJAIhhwVyFHrVfMA0GCSqGSIb3DQEBBQUAMG8xCzAJBgNV\nBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX\naWRnaXRzIFB0eSBMdGQxCjAIBgNVBAsTAWExCjAIBgNVBAMTAWIxEDAOBgkqhkiG\n9w0BCQEWAWMwHhcNMTIwMjE5MDExMzQxWhcNMTUwMjE4MDExMzQxWjBvMQswCQYD\nVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQg\nV2lkZ2l0cyBQdHkgTHRkMQowCAYDVQQLEwFhMQowCAYDVQQDEwFiMRAwDgYJKoZI\nhvcNAQkBFgFjMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAM4Aozh3TMZYcPx7MHln\nD8MtyVUjzo6OdT32JwRHzHHNMMm88lNVfLYIT9C/jgXlDqG0h5wSClMvTQbdihNd\nFOkCAwEAAaOB1DCB0TAdBgNVHQ4EFgQUv0Ahb7HD9TLfdtLeaatjFj91NqYwgaEG\nA1UdIwSBmTCBloAUv0Ahb7HD9TLfdtLeaatjFj91Nqahc6RxMG8xCzAJBgNVBAYT\nAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRn\naXRzIFB0eSBMdGQxCjAIBgNVBAsTAWExCjAIBgNVBAMTAWIxEDAOBgkqhkiG9w0B\nCQEWAWOCCQCIYcFchR61XzAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA0EA\nKAbxbWHsaVPnYc0YqG/Pn4HbcI1+xnVQSt3hdzq+yC0lP9H7hBMCVSykhhBkZ5XQ\nHA2t6LHuYsjcCO+LBX/4fA==\n-----END CERTIFICATE-----"} -------------------------------------------------------------------------------- /google-api-php-client/tests/general/testdata/cacert.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICrDCCAlagAwIBAgIJAIhhwVyFHrVfMA0GCSqGSIb3DQEBBQUAMG8xCzAJBgNV 3 | BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX 4 | aWRnaXRzIFB0eSBMdGQxCjAIBgNVBAsTAWExCjAIBgNVBAMTAWIxEDAOBgkqhkiG 5 | 9w0BCQEWAWMwHhcNMTIwMjE5MDExMzQxWhcNMTUwMjE4MDExMzQxWjBvMQswCQYD 6 | VQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQg 7 | V2lkZ2l0cyBQdHkgTHRkMQowCAYDVQQLEwFhMQowCAYDVQQDEwFiMRAwDgYJKoZI 8 | hvcNAQkBFgFjMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAM4Aozh3TMZYcPx7MHln 9 | D8MtyVUjzo6OdT32JwRHzHHNMMm88lNVfLYIT9C/jgXlDqG0h5wSClMvTQbdihNd 10 | FOkCAwEAAaOB1DCB0TAdBgNVHQ4EFgQUv0Ahb7HD9TLfdtLeaatjFj91NqYwgaEG 11 | A1UdIwSBmTCBloAUv0Ahb7HD9TLfdtLeaatjFj91Nqahc6RxMG8xCzAJBgNVBAYT 12 | AkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRn 13 | aXRzIFB0eSBMdGQxCjAIBgNVBAsTAWExCjAIBgNVBAMTAWIxEDAOBgkqhkiG9w0B 14 | CQEWAWOCCQCIYcFchR61XzAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA0EA 15 | KAbxbWHsaVPnYc0YqG/Pn4HbcI1+xnVQSt3hdzq+yC0lP9H7hBMCVSykhhBkZ5XQ 16 | HA2t6LHuYsjcCO+LBX/4fA== 17 | -----END CERTIFICATE----- -------------------------------------------------------------------------------- /google-api-php-client/tests/general/testdata/cert.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/visualbasic6/google-drive-infoleak/af3c059a914edfe427e44466fa7930e831cc37dd/google-api-php-client/tests/general/testdata/cert.p12 -------------------------------------------------------------------------------- /google-api-php-client/tests/general/testdata/privkey.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIBOwIBAAJBAM4Aozh3TMZYcPx7MHlnD8MtyVUjzo6OdT32JwRHzHHNMMm88lNV 3 | fLYIT9C/jgXlDqG0h5wSClMvTQbdihNdFOkCAwEAAQJBAJuMo7KpcpF6iqY7Jtkk 4 | 1yQb2KCvTvMZ4rGMwt1akaeDW2noyqCeO675gFBtlizgcRsybealQVQgGX4E5VqF 5 | UJkCIQDzJZZi2jloDXcyyy2rEa4mj4RnrnIYsDMJ55XMWJ9c9wIhANjkY97FSRX3 6 | WSdRFqXd3Pc4URUho+rCcPibafMOwAUfAiAa58ngXm2DyhmqkTkYePhgY/kuz+ro 7 | OHctXWcCGbxouQIgLC5qAakieC0Ipi+oc2U8a8e3DJzrrRiqtpnB/VcV2nUCIQC2 8 | DXrpyt6jjVIzs4jI5Cl3QGLL6TZ8FqpyonU/1ARuhA== 9 | -----END RSA PRIVATE KEY----- -------------------------------------------------------------------------------- /google-api-php-client/tests/general/testdata/test.ini: -------------------------------------------------------------------------------- 1 | ; Test.ini file 2 | application_name = My Test application 3 | auth_class = Google_Auth_OAuth2 4 | [classes] 5 | Google_Auth_OAuth2[client_id] = 12345.apps.googleusercontent.com 6 | Google_Auth_OAuth2[client_secret] = gjfiwnGinpena3 7 | Google_Auth_OAuth2[redirect_uri] = http://example.com -------------------------------------------------------------------------------- /google-api-php-client/tests/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/tests/pagespeed/PageSpeedTest.php: -------------------------------------------------------------------------------- 1 | service = new Google_Service_Pagespeedonline($this->getClient()); 25 | } 26 | 27 | public function testPageSpeed() 28 | { 29 | $this->checkToken(); 30 | $psapi = $this->service->pagespeedapi; 31 | $result = $psapi->runpagespeed('http://code.google.com'); 32 | $this->assertArrayHasKey('kind', $result); 33 | $this->assertArrayHasKey('id', $result); 34 | $this->assertArrayHasKey('responseCode', $result); 35 | $this->assertArrayHasKey('title', $result); 36 | $this->assertArrayHasKey('score', $result); 37 | $this->assertInstanceOf('Google_Service_Pagespeedonline_ResultPageStats', $result->pageStats); 38 | $this->assertArrayHasKey('minor', $result['version']); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /google-api-php-client/tests/plus/PlusTest.php: -------------------------------------------------------------------------------- 1 | plus = new Google_Service_Plus($this->getClient()); 26 | } 27 | 28 | public function testGetPerson() 29 | { 30 | $this->checkToken(); 31 | $person = $this->plus->people->get("118051310819094153327"); 32 | $this->assertArrayHasKey('kind', $person); 33 | $this->assertArrayHasKey('displayName', $person); 34 | $this->assertArrayHasKey('gender', $person); 35 | $this->assertArrayHasKey('id', $person); 36 | } 37 | 38 | public function testListActivities() 39 | { 40 | $this->checkToken(); 41 | $activities = $this->plus->activities 42 | ->listActivities("118051310819094153327", "public"); 43 | 44 | $this->assertArrayHasKey('kind', $activities); 45 | $this->assertGreaterThan(0, count($activities)); 46 | 47 | // Test a variety of access methods. 48 | $this->assertItem($activities['items'][0]); 49 | $this->assertItem($activities[0]); 50 | foreach ($activities as $item) { 51 | $this->assertItem($item); 52 | break; 53 | } 54 | 55 | // Test deeper type transformations 56 | $this->assertGreaterThan(0, strlen($activities[0]->actor->displayName)); 57 | } 58 | 59 | public function assertItem($item) 60 | { 61 | // assertArrayHasKey uses array_key_exists, which is not great: 62 | // it doesn't understand SPL ArrayAccess 63 | $this->assertTrue(isset($item['actor'])); 64 | $this->assertInstanceOf('Google_Service_Plus_ActivityActor', $item->actor); 65 | $this->assertTrue(isset($item['actor']['displayName'])); 66 | $this->assertTrue(isset($item['actor']->url)); 67 | $this->assertTrue(isset($item['object'])); 68 | $this->assertTrue(isset($item['access'])); 69 | $this->assertTrue(isset($item['provider'])); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /google-api-php-client/tests/tasks/TasksTest.php: -------------------------------------------------------------------------------- 1 | taskService = new Google_Service_Tasks($this->getClient()); 27 | } 28 | 29 | public function testInsertTask() 30 | { 31 | if (!$this->checkToken()) { 32 | return; 33 | } 34 | $list = $this->createTaskList('List: ' . __METHOD__); 35 | $task = $this->createTask('Task: '.__METHOD__, $list->id); 36 | $this->assertIsTask($task); 37 | } 38 | 39 | /** 40 | * @depends testInsertTask 41 | */ 42 | public function testGetTask() 43 | { 44 | $tasks = $this->taskService->tasks; 45 | $list = $this->createTaskList('List: ' . __METHOD__); 46 | $task = $this->createTask('Task: '. __METHOD__, $list['id']); 47 | 48 | $task = $tasks->get($list['id'], $task['id']); 49 | $this->assertIsTask($task); 50 | } 51 | 52 | /** 53 | * @depends testInsertTask 54 | */ 55 | public function testListTask() 56 | { 57 | $tasks = $this->taskService->tasks; 58 | $list = $this->createTaskList('List: ' . __METHOD__); 59 | 60 | for ($i=0; $i<4; $i++) { 61 | $this->createTask("Task: $i ".__METHOD__, $list['id']); 62 | } 63 | 64 | $tasksArray = $tasks->listTasks($list['id']); 65 | $this->assertTrue(sizeof($tasksArray) > 1); 66 | foreach ($tasksArray['items'] as $task) { 67 | $this->assertIsTask($task); 68 | } 69 | } 70 | 71 | private function createTaskList($name) 72 | { 73 | $list = new Google_Service_Tasks_TaskList(); 74 | $list->title = $name; 75 | return $this->taskService->tasklists->insert($list); 76 | } 77 | 78 | private function createTask($title, $listId) 79 | { 80 | $tasks = $this->taskService->tasks; 81 | $task = new Google_Service_Tasks_Task(); 82 | $task->title = $title; 83 | return $tasks->insert($listId, $task); 84 | } 85 | 86 | private function assertIsTask($task) 87 | { 88 | $this->assertArrayHasKey('title', $task); 89 | $this->assertArrayHasKey('kind', $task); 90 | $this->assertArrayHasKey('id', $task); 91 | $this->assertArrayHasKey('position', $task); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /google-api-php-client/tests/urlshortener/UrlShortenerTests.php: -------------------------------------------------------------------------------- 1 | service = new Google_Service_Urlshortener($this->getClient()); 27 | } 28 | 29 | public function testUrlShort() 30 | { 31 | $url = new Google_Service_Urlshortener_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 | { 41 | $optParams = array('fields' => ''); 42 | $resp = $this->service->url->get('http://goo.gl/KkHq8', $optParams); 43 | 44 | $this->assertEquals("", $resp->longUrl); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /google-api-php-client/tests/youtube/YouTubeTest.php: -------------------------------------------------------------------------------- 1 | youtube = new Google_Service_YouTube($this->getClient()); 26 | } 27 | 28 | public function testMissingFieldsAreNull() 29 | { 30 | if (!$this->checkToken()) { 31 | return; 32 | } 33 | 34 | $parts = "id,brandingSettings"; 35 | $opts = array("mine" => true); 36 | $channels = $this->youtube->channels->listChannels($parts, $opts); 37 | 38 | $newChannel = new Google_Service_YouTube_Channel(); 39 | $newChannel->setId($channels[0]->getId()); 40 | $newChannel->setBrandingSettings($channels[0]->getBrandingSettings()); 41 | 42 | $simpleOriginal = $channels[0]->toSimpleObject(); 43 | $simpleNew = $newChannel->toSimpleObject(); 44 | 45 | $this->assertObjectHasAttribute('etag', $simpleOriginal); 46 | $this->assertObjectNotHasAttribute('etag', $simpleNew); 47 | 48 | $owner_details = new Google_Service_YouTube_ChannelContentOwnerDetails(); 49 | $owner_details->setTimeLinked("123456789"); 50 | $o_channel = new Google_Service_YouTube_Channel(); 51 | $o_channel->setContentOwnerDetails($owner_details); 52 | $simpleManual = $o_channel->toSimpleObject(); 53 | $this->assertObjectHasAttribute('timeLinked', $simpleManual->contentOwnerDetails); 54 | $this->assertObjectNotHasAttribute('contentOwner', $simpleManual->contentOwnerDetails); 55 | 56 | $owner_details = new Google_Service_YouTube_ChannelContentOwnerDetails(); 57 | $owner_details->timeLinked = "123456789"; 58 | $o_channel = new Google_Service_YouTube_Channel(); 59 | $o_channel->setContentOwnerDetails($owner_details); 60 | $simpleManual = $o_channel->toSimpleObject(); 61 | 62 | $this->assertObjectHasAttribute('timeLinked', $simpleManual->contentOwnerDetails); 63 | $this->assertObjectNotHasAttribute('contentOwner', $simpleManual->contentOwnerDetails); 64 | 65 | $owner_details = new Google_Service_YouTube_ChannelContentOwnerDetails(); 66 | $owner_details['timeLinked'] = "123456789"; 67 | $o_channel = new Google_Service_YouTube_Channel(); 68 | $o_channel->setContentOwnerDetails($owner_details); 69 | $simpleManual = $o_channel->toSimpleObject(); 70 | 71 | $this->assertObjectHasAttribute('timeLinked', $simpleManual->contentOwnerDetails); 72 | $this->assertObjectNotHasAttribute('contentOwner', $simpleManual->contentOwnerDetails); 73 | 74 | $ping = new Google_Service_YouTube_ChannelConversionPing(); 75 | $ping->setContext("hello"); 76 | $pings = new Google_Service_YouTube_ChannelConversionPings(); 77 | $pings->setPings(array($ping)); 78 | $simplePings = $pings->toSimpleObject(); 79 | $this->assertObjectHasAttribute('context', $simplePings->pings[0]); 80 | $this->assertObjectNotHasAttribute('conversionUrl', $simplePings->pings[0]); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /index_files/formoid1/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Header set Access-Control-Allow-Origin "*" 4 | 5 | -------------------------------------------------------------------------------- /index_files/formoid1/form.formoid: -------------------------------------------------------------------------------- 1 | {"elements":[{"label":"target@gmail.com","name":"input","hover":"enter your target's gmail address","required":false,"pattern":"","fieldSize":"large","type":"input"}],"title":"gmail full name disclosure","template":"solid-red","email":"","fontSize":9,"fontFamily":"Arial,Helvetica,sans-serif","fontColor":"#34495E","width":"480px","bgcolor":"#FFFFFF","pageColor":"#EBEBEB","submit":"reveal","confirm":"redirect","message":"","redirect":"reveal.php?target=","blurBg":false,"injectCSS":"","feedback":"","labelType":"placeholder","elementIcon":true} -------------------------------------------------------------------------------- /index_files/formoid1/form.php: -------------------------------------------------------------------------------- 1 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |

gmail full name disclosure

23 |
" title="enter your target's gmail address">
24 |
25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /index_files/formoid1/formoid.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/visualbasic6/google-drive-infoleak/af3c059a914edfe427e44466fa7930e831cc37dd/index_files/formoid1/formoid.eot -------------------------------------------------------------------------------- /index_files/formoid1/formoid.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Generated by IcoMoon 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /index_files/formoid1/formoid.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/visualbasic6/google-drive-infoleak/af3c059a914edfe427e44466fa7930e831cc37dd/index_files/formoid1/formoid.ttf -------------------------------------------------------------------------------- /index_files/formoid1/formoid.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/visualbasic6/google-drive-infoleak/af3c059a914edfe427e44466fa7930e831cc37dd/index_files/formoid1/formoid.woff -------------------------------------------------------------------------------- /index_files/formoid1/helpers.php: -------------------------------------------------------------------------------- 1 | $v) { 9 | unset($process[$key][$k]); 10 | if (is_array($v)) { 11 | $process[$key][stripslashes($k)] = $v; 12 | $process[] = &$process[$key][stripslashes($k)]; 13 | } else { 14 | $process[$key][stripslashes($k)] = stripslashes($v); 15 | } 16 | } 17 | } 18 | unset($process); 19 | } else if (version_compare(PHP_VERSION, '5.3.0', '>=')) 20 | ini_set('magic_quotes_runtime', 0); 21 | else set_magic_quotes_runtime(0); 22 | } 23 | 24 | /** file_get_contents */ 25 | if (!function_exists('file_get_contents')){ 26 | function file_get_contents($path){ 27 | if (!file_exists($path)) return false; 28 | $fh = fopen($path, 'r'); 29 | $data = fread($fh, filesize($path)); 30 | fclose($fh); 31 | return $data; 32 | } 33 | } 34 | 35 | /** file_put_contents */ 36 | if (!function_exists('file_put_contents')){ 37 | function file_put_contents($path, $data){ 38 | if (!$fp = fopen($path, 'a')) return false; 39 | flock($fp, LOCK_EX); 40 | ftruncate($fp, 0); 41 | fputs($fp, $data); 42 | fflush($fp); 43 | flock($fp, LOCK_UN); 44 | fclose($fp); 45 | return true; 46 | } 47 | } 48 | 49 | /** mb_strlen */ 50 | if (!function_exists('mb_strlen')){ 51 | function mb_strlen($s){ 52 | return preg_match_all('/[\x00-\x7F\xC0-\xFD]/', $s, $d); 53 | } 54 | } else if (function_exists('mb_internal_encoding')){ 55 | mb_internal_encoding( 56 | (defined('PAGE_ENCODING') ? PAGE_ENCODING : 'UTF-8') 57 | ); 58 | } 59 | 60 | /** json_decode */ 61 | if (!function_exists('json_decode')){ 62 | require_once _DIR_ . 'JSON.php'; 63 | function json_decode($json, $assoc = false){ 64 | if ($assoc) $obj = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); 65 | else $obj = new Services_JSON(); 66 | return $obj -> decode($json); 67 | } 68 | } 69 | 70 | ?> 71 | -------------------------------------------------------------------------------- /index_files/formoid1/icons.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/visualbasic6/google-drive-infoleak/af3c059a914edfe427e44466fa7930e831cc37dd/index_files/formoid1/icons.eot -------------------------------------------------------------------------------- /index_files/formoid1/icons.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Copyright (C) 2014 by original authors @ fontello.com 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /index_files/formoid1/icons.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/visualbasic6/google-drive-infoleak/af3c059a914edfe427e44466fa7930e831cc37dd/index_files/formoid1/icons.ttf -------------------------------------------------------------------------------- /index_files/formoid1/icons.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/visualbasic6/google-drive-infoleak/af3c059a914edfe427e44466fa7930e831cc37dd/index_files/formoid1/icons.woff --------------------------------------------------------------------------------