【发布时间】:2016-02-16 07:30:48
【问题描述】:
谁能告诉我在哪里可以找到一些关于如何将谷歌日历 API 集成到 codeigniter 框架的信息。
我关注these steps,一切似乎都很好,但现在我不知道如何继续。
我按照这些步骤获得的所有文件(json、库和 quickstart.php)我都将它们放在框架的库文件夹中......对吗??
有没有这方面的教程??
编辑
我在做一些尝试,但我得到了一些错误...例如我尝试按照this page的例子,它看起来很简单:
$calendarListEntry = $service->calendarList->get('calendarId');
echo $calendarListEntry->getSummary();
但是... $service 从哪里得到?我正在查看客户端库的示例,并且有一个文件调用 simple-query-php,其中使用了一个名为 Google_Service_Books 的类,其中对象的名称是 $service,我试图将这两个来源混合起来,结果是这样的:
require_once('Google/autoload.php');
$client = new Google_Client();
$client->setApplicationName("My_application_name");
$apiKey = "my-client-secret";
$client->setDeveloperKey($apiKey);
$service = new Google_Service_Books($client);
$calendarListEntry = $service->calendarList->get('calendarId');
echo $calendarListEntry->getSummary();
执行中有疑问和错误。
疑问,在这一行: $apiKey = "my-client-secret";它通过 API-KEY 询问,但我输入了 client_secret... 是一样的吗?
错误:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Google_Service_Books::$calendarList
Filename: controllers/dashboard.php
Line Number: 17
Fatal error: Call to a member function get() on a non-object in /var/www/html/prototipo/application/controllers/dashboard.php on line 17
我怎样才能得到正确的 $service 对象??
谢谢
重新编辑
ANSWER ABOUT APIKEY 我觉得不一样,我输入的是创建 OAuth 2.0 客户端 ID 凭据后获取的客户端密码,现在我创建了一个新凭据:API KEY-> 服务器键。
我认为现在我得到了正确的类来获取正确的 $service 对象,但我发现了另一个新问题。我正在尝试的是:
require_once('Google/autoload.php');
$client = new Google_Client();
$client->setApplicationName("CalendarTest");
$apiKey = "APY-KEY";
$client->setDeveloperKey($apiKey);
$service = new Google_Service_Calendar($client);
$calendarListEntry = $service->calendarList->get('primary');
echo $calendarListEntry->getSummary();
在浏览器上调用这个方法的结果是这样的:
致命错误:/home/vendor/google/apiclient/src/Google/Http/REST.php:110 中的未捕获异常“Google_Service_Exception”和消息“错误调用 GET https://www.googleapis.com/calendar/v3/users/me/calendarList/calendarId?key=MY-APY-KEY: (401) 需要登录”堆栈跟踪: #0 /home/vendor/google/apiclient/src/Google/Http/REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client)) #1 [内部函数]: Google_Http_REST:: doExecute(Object(Google_Client), Object(Google_Http_Request)) #2 /home/vendor/google/apiclient/src/Google/Task/Runner.php(174): call_user_func_array(Array, Array) #3 /home/vendor/google /apiclient/src/Google/Http/REST.php(46): Google_Task_Runner->run() #4 /home/vendor/google/apiclient/src/Google/Client.php(593): Google_Http_REST::execute(Object (Google_Client), Object(Google_Http_Request)) #5 /home/vendor/google/apiclient/src/Google/Service/Resource.php(240): Google_Client->execute(Object(Google_Http_Request)) #6 /home/vendor/ google/apiclient/src/进入/home/vendor/google/apiclient/src/Google/Http /REST.php 在第 110 行
如果我删除有关 applicationName 和 apikey 的行,结果相同。需要登录??什么意思??
谢谢。
【问题讨论】:
标签: codeigniter google-calendar-api google-api-php-client