doujia7094 2014-04-04 13:15
浏览 77
已采纳

在laravel中为Google日历添加Google php API

I want to use the Google php api for accessing the calendars. I'm working with laravel. I already added the package on composer and it's downloading fine, the thing is what I have to do with the providers and aliases or whatever to link the api with my app. I want to call the Calendar class. I do the auth properly to with another library, artdarek/oauth-4-laravel, i can show the calendar with this api but i can't insert/edit calendar, is this a simpler way ?

Here 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's 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"
},

The method for adding a calendar

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();
}

Hope you can help me ! Thanks !

  • 写回答

2条回答 默认 最新

  • douxia3505 2014-05-09 06:16
    关注

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

    "google/apiclient": "dev-master"
    

    run

    composer update

    Now you can use the 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 could store your client id and secret stored in a config file.

    You don't need to add the library path to the providers list.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装