Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
dwsupplee committed Dec 3, 2015
1 parent 3de62fd commit 6be1859
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,33 @@ As long as you update the environment variable below to point to *your* JSON
credentials file, the following code should output a list of your Drive files.

```php
use GuzzleHttp\Client;
use Google\Auth\ApplicationDefaultCredentials;
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;

// specify the path to your application credentials
putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/my/credentials.json');

// define the scopes for your API call
$scopes = ['https://www.googleapis.com/auth/drive.readonly'];

// create middleware
$middleware = ApplicationDefaultCredentials::getMiddleware($scopes);
$stack = HandlerStack::create();
$stack->push($middleware);

// create the HTTP client
$client = new Client([
'handler' => $stack
'base_url' => 'https://www.googleapis.com',
'defaults' => ['auth' => 'google_auth'] // authorize all requests
'auth' => 'google_auth' // authorize all requests
]);

// attach this library's auth listener
$fetcher = ApplicationDefaultCredentials::getFetcher($scopes);
$client->getEmitter()->attach($fetcher);

// make the request
$response = $client->get('drive/v2/files');

// show the result!
print_r($response->json());
print_r((string) $response->getBody());
```

## What about auth in google-apis-php-client?
Expand Down

0 comments on commit 6be1859

Please sign in to comment.