Adding Google php API for Google Calendar in laravel

I want to use google php api to access calendars. I work with laravel. I already added the package to the composer, and it downloads everything that I have to do with providers and aliases or something to associate api with my application. I want to call the Calendar class. I am doing auth correctly with another library, artdarek / oauth-4-laravel, I can show the calendar with this api, but I can not insert / edit the calendar, is it easier?

Here are the providers:

'providers' => array( 'Illuminate\Foundation\Providers\ArtisanServiceProvider', 'Illuminate\Auth\AuthServiceProvider', 'Illuminate\Cache\CacheServiceProvider', 'Illuminate\Session\CommandsServiceProvider', 'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider', 'Illuminate\Routing\ControllerServiceProvider', 'Illuminate\Cookie\CookieServiceProvider', 'Illuminate\Database\DatabaseServiceProvider', 'Illuminate\Encryption\EncryptionServiceProvider', 'Illuminate\Filesystem\FilesystemServiceProvider', 'Illuminate\Hashing\HashServiceProvider', 'Illuminate\Html\HtmlServiceProvider', 'Illuminate\Log\LogServiceProvider', 'Illuminate\Mail\MailServiceProvider', 'Illuminate\Database\MigrationServiceProvider', 'Illuminate\Pagination\PaginationServiceProvider', 'Illuminate\Queue\QueueServiceProvider', 'Illuminate\Redis\RedisServiceProvider', 'Illuminate\Remote\RemoteServiceProvider', 'Illuminate\Auth\Reminders\ReminderServiceProvider', 'Illuminate\Database\SeedServiceProvider', 'Illuminate\Session\SessionServiceProvider', 'Illuminate\Translation\TranslationServiceProvider', 'Illuminate\Validation\ValidationServiceProvider', 'Illuminate\View\ViewServiceProvider', 'Illuminate\Workbench\WorkbenchServiceProvider', 'Artdarek\OAuth\OAuthServiceProvider', 'Google\Client', ), 

Here are the aliases:

 'aliases' => array( 'App' => 'Illuminate\Support\Facades\App', 'Artisan' => 'Illuminate\Support\Facades\Artisan', 'Auth' => 'Illuminate\Support\Facades\Auth', 'Blade' => 'Illuminate\Support\Facades\Blade', 'Cache' => 'Illuminate\Support\Facades\Cache', 'ClassLoader' => 'Illuminate\Support\ClassLoader', 'Config' => 'Illuminate\Support\Facades\Config', 'Controller' => 'Illuminate\Routing\Controller', 'Cookie' => 'Illuminate\Support\Facades\Cookie', 'Crypt' => 'Illuminate\Support\Facades\Crypt', 'DB' => 'Illuminate\Support\Facades\DB', 'Eloquent' => 'Illuminate\Database\Eloquent\Model', 'Event' => 'Illuminate\Support\Facades\Event', 'File' => 'Illuminate\Support\Facades\File', 'Form' => 'Illuminate\Support\Facades\Form', 'Hash' => 'Illuminate\Support\Facades\Hash', 'HTML' => 'Illuminate\Support\Facades\HTML', 'Input' => 'Illuminate\Support\Facades\Input', 'Lang' => 'Illuminate\Support\Facades\Lang', 'Log' => 'Illuminate\Support\Facades\Log', 'Mail' => 'Illuminate\Support\Facades\Mail', 'Paginator' => 'Illuminate\Support\Facades\Paginator', 'Password' => 'Illuminate\Support\Facades\Password', 'Queue' => 'Illuminate\Support\Facades\Queue', 'Redirect' => 'Illuminate\Support\Facades\Redirect', 'Redis' => 'Illuminate\Support\Facades\Redis', 'Request' => 'Illuminate\Support\Facades\Request', 'Response' => 'Illuminate\Support\Facades\Response', 'Route' => 'Illuminate\Support\Facades\Route', 'Schema' => 'Illuminate\Support\Facades\Schema', 'Seeder' => 'Illuminate\Database\Seeder', 'Session' => 'Illuminate\Support\Facades\Session', 'SSH' => 'Illuminate\Support\Facades\SSH', 'Str' => 'Illuminate\Support\Str', 'URL' => 'Illuminate\Support\Facades\URL', 'Validator' => 'Illuminate\Support\Facades\Validator', 'View' => 'Illuminate\Support\Facades\View', 'OAuth' => 'Artdarek\OAuth\Facade\OAuth', 'Calendar' => 'Google\Service\Calendar' ), 

Composer.json

  "require": { "laravel/framework": "4.1.*", "artdarek/oauth-4-laravel": "dev-master", "google/apiclient": "dev-master" }, 

Calendar Addition Method

 public function addCalendar($calendarName){ $calendar = new Calendar(); $calendar->setSummary($calendarName); // get google service $googleService = OAuth::consumer( 'Google' ); $createdCalendar = $googleService->calendars->insert($calendar); echo $createdCalendar->getId(); } 

I hope you help me! Thanks!

+7
php google-calendar laravel laravel-4 google-api-php-client
source share
2 answers

After you have added the google library to the require block of your composer.json file, this line:

 "google/apiclient": "dev-master" 

run

Composer Update

Now you can use google client library in your controller

 $google_client = new Google_Client(); $google_client->setApplicationName('YOUR APPLICATION NAME'); $google_client->setClientId('YOUR CLIENT ID'); $google_client->setClientSecret('SECRET'); 

Of course, you can keep your client ID and secret stored in the configuration file.

You do not need to add the library path to the vendor list.

+5
source share

In its current form (as far as I know) this library is not intended for easy use in Laravel. It does not contain the Laravel service provider (which will be delivered on your provider networks) or the Facade class, which will be in your array of aliases.

When I tried to use this API, I went and received an unofficial package containing namespaces, then whenever I wanted to use code, I would just name it through its namespace, for example

 $client = new \Google\Client(); // Sets the class to use objects $client->setUseObjects(true); // Initiates Calendar Class injecting the $client class $cal = new \Google\CalendarService($client); 

if you were configured to use the official library, I believe that you will need to include files, for example.

 include('vendor/google/client...'); 

And follow the github tutorial on using the package.

Hope this helps

+1
source share

All Articles