Download the PHP package isometriks/google-api-bundle without Composer
On this page you can find all versions of the php package isometriks/google-api-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download isometriks/google-api-bundle
More information about isometriks/google-api-bundle
Files in isometriks/google-api-bundle
Package google-api-bundle
Short Description Symfony2 Bundle for using Google APIs
License MIT
Informations about the package google-api-bundle
Google API
Installation
Add routing:
Note: Your redirect_uri
below and in the developer console should match
that of the isometriks_google_redirect
route. So if you do as above, then
redirect_uri below in dev environment should be:
http://example.com/app_dev.php/google/redirect and without app_dev.php for
production. redirect_route
will generate redirect_uri
.
Configuration:
Controller Annotations
Without Annotations
Token Storage
By default the system will use sessions to store the tokens. If you are going
to be using refresh tokens (type = offline
) then this won't work well as
destroying the session will destroy your refresh token since you only get
one the very first time you authorize. In this case you can create your own
storage, or if you need to store tokens for users we provide an abstract class
to help with that.
Example of User storage:
And remember to change the config:
You can extend the abstract service we provide: isometriks_google_api.storage.user_storage
As noted in the above class you will need to either add setter injection or add an argument
to the constructor so you can make sure that the user is persisted in your ORM / other implementation.
Display a "Connect" screen
You can easily attach into the events to display a "connect" button view before
sending the user to Google for the token using the Events::OAUTH_PRE_AUTH
event:
<?php
// ...
class PreAuthListener implements EventSubscriberInterface
{
protected $twig;
public function __construct(\Twig_Environment $twig)
{
$this->twig = $twig;
}
public function onPreAuth(ClientEvent $event)
{
// Or use your own template, ours is mostly just an example
$content = $this->twig->render('IsometriksGoogleApiBundle:OAuth:connect.html.twig', array(
'auth_url' => $event->getClient()->createAuthUrl(),
));
$event->setResponse(new Response($content));
}
public static function getSubscribedEvents()
{
return array(
Events::OAUTH_PRE_AUTH => 'onPreAuth',
);
}
}