PHP code example of isometriks / google-api-bundle
1. Go to this page and download the library: Download isometriks/google-api-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
isometriks / google-api-bundle example snippets
namespace AppBundle\Controller;
use Isometriks\Bundle\GoogleApiBundle\Annotation\GoogleScope;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
/**
* @GoogleScope({"gmail.readonly"})
*/
class MyController extends Controller
{
/**
* @GoogleScope({"analytics.readonly", "calendar.readonly"})
*/
public function indexAction()
{
// Will only execute if we have all 3 permissions
// Use the services available in the Google PHP API
$client = $this->get('isometriks_google_api.client');
$analytics = new \Google_Service_Analytics($client);
var_dump($analytics->management_accounts->listManagementAccounts()); // etc
}
}
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class MyController extends Controller
{
/**
* @Route("/", name="homepage")
*/
public function indexAction()
{
$scopeManager = $this->get('isometriks_google_api.scope_manager');
if (!$scopeManager->hasScope('calendar.readonly')) {
return $this->redirect($scopeManager->obtainScopeUrl(
array('calendar.readonly'),
$this->generateUrl('homepage')
));
}
// obtainScopeUrl(array $scopes, $returnUrl)
}
}
bash
$ php composer.phar
namespace AppBundle\Storage;
use Isometriks\Bundle\GoogleApiBundle\Storage\UserStorage as BaseUserStorage;
class UserStorage extends BaseUserStorage
{
public function getToken()
{
return $this->getUser()->getToken();
}
public function hasToken()
{
return $this->getUser() && $this->getUser()->getToken();
}
public function removeToken()
{
$this->getUser()->setToken(null);
// Persist Doctrine / Propel etc..
}
public function setToken($token)
{
$this->getUser()->setToken($token);
// Persist Doctrine / Propel etc..
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.