appengineauth.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /*
  3. * Copyright 2013 Google Inc.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. session_start();
  18. include_once "templates/base.php";
  19. /************************************************
  20. Make an API request authenticated via the
  21. AppIdentity service on AppEngine.
  22. ************************************************/
  23. require_once realpath(dirname(__FILE__) . '/../src/Google/autoload.php');
  24. echo pageHeader("AppIdentity Account Access");
  25. $client = new Google_Client();
  26. $client->setApplicationName("Client_Library_Examples");
  27. $auth = new Google_Auth_AppIdentity($client);
  28. $token = $auth->authenticateForScope(Google_Service_Storage::DEVSTORAGE_READ_ONLY);
  29. if (!$token) {
  30. die("Could not authenticate to AppIdentity service");
  31. }
  32. $client->setAuth($auth);
  33. $service = new Google_Service_Storage($client);
  34. $results = $service->buckets->listBuckets(str_replace("s~", "", $_SERVER['APPLICATION_ID']));
  35. echo "<h3>Results Of Call:</h3>";
  36. echo "<pre>";
  37. var_dump($results);
  38. echo "</pre>";
  39. echo pageFooter(__FILE__);