[英]Adding Google php API for google calendar in laravel
我想使用Google php api訪問日歷。 我正在和laravel一起工作。 我已經在作曲家上添加了這個包並且下載得很好,這就是我與提供者和別名或者用我的應用程序鏈接api的任何事情。 我想調用Calendar類。 我正確地使用另一個庫,artdarek / oauth-4-laravel,我可以用這個api顯示日歷,但我不能插入/編輯日歷,這是一個更簡單的方法嗎?
提供者:
'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',
),
這是別名:
'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"
},
添加日歷的方法
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();
}
希望你能幫我 ! 謝謝 !
添加Google庫后,在composer.json文件的require塊中,此行:
"google/apiclient": "dev-master"
跑
作曲家更新
現在,您可以在控制器中使用Google客戶端庫
$google_client = new Google_Client();
$google_client->setApplicationName('YOUR APPLICATION NAME');
$google_client->setClientId('YOUR CLIENT ID');
$google_client->setClientSecret('SECRET');
當然,您可以存儲存儲在配置文件中的客戶端ID和秘密。
您不需要將庫路徑添加到提供程序列表。
在目前的形式(據我所知),這個庫不是為在Laravel中使用而設計的。 它不包含Laravel服務提供程序(將在您的提供程序數組中)或將包含在別名數組中的Facade類。
當我嘗試使用這個API時,我去了一個包含命名空間的非官方包,然后每當我想使用代碼時,我只會通過它的命名空間調用它,例如
$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);
如果您開始使用官方庫我相信您需要包含文件,例如
include('vendor/google/client...');
並遵循使用該軟件包的github指南。
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.