正在开发导出并使用Codeigniter和Google ApiService / apiCalendarService导入Google Calendar应用程序.当我从此页面向Google授权我的应用程序时,我已经完成了所有设置,没有任何问题:
session_start();
require(APPPATH . 'libraries/google/apiclient.PHP');
require(APPPATH . 'libraries/google/contrib/apiCalendarService.PHP');
$apiclient = new apiclient();
$apiclient->setUSEObjects(true);
$calendarService = new apiCalendarService($apiclient);
if(isset($_SESSION['oauth_access_token']))
{
$apiclient->setAccesstoken($_SESSION['oauth_access_token']);
}
else
{
$token = $apiclient->authenticate();
$_SESSION['oauth_access_token'] = $token;
}
在进行身份验证后,我会使用我的URL中的选项重定向回我的localhost站点:
http://localhost/project/acp/sync/auth/?code=4/DS91JtSJ5_9Q-Z55Kpyh2AicyWdL
我的脚本将通过使用auth和代码查询字符串检查URI段来检测何时进行了身份验证 – 因此我可以开始将事件导入我的Google日历帐户,直到我抛出此错误:
Fatal error: Uncaught exception 'apiServiceException' with message 'Error calling POST https://www.googleapis.com/calendar/v3/calendars/primary/events?key={removed API key}: (401) Login required' in /Users/Me/Sites/project/application/libraries/google/io/apiREST.PHP:86
Stack trace:
#0 /Users/Me/Sites/project/application/libraries/google/io/apiREST.PHP(56): apiREST::decodeHttpResponse(Object(apiHttpRequest))
#1 /Users/Me/Sites/project/application/libraries/google/service/apiServiceResource.PHP(187): apiREST::execute(Object(apiServiceRequest))
#2 /Users/Me/Sites/project/application/libraries/google/contrib/apiCalendarService.PHP(493): apiServiceResource->__call('insert', Array)
#3 /Users/Me/Sites/project/application/controllers/acp/panel.PHP(2053): EventsServiceResource->insert('primary', Object(Event))
#4 [internal function]: Panel->sync('auth')
#5 /Users/Me/Sites/project/system/core/CodeIgniter.PHP(359): call_user_func_array(Array, Array)
#6 /Users/Me in /Users/Me/Sites/project/application/libraries/google/io/apiREST.PHP on line 86
导入事件的代码(代码来自Google Api示例):
session_start();
require(APPPATH . 'libraries/google/apiclient.PHP');
require(APPPATH . 'libraries/google/contrib/apiCalendarService.PHP');
$apiclient = new apiclient();
$apiclient->setUSEObjects(true);
$service = new apiCalendarService($apiclient);
$event = new Event();
$event->setSummary('Appointment');
$event->setLocation('Somewhere');
$start = new EventDateTime();
$start->setDateTime('2011-06-03T10:00:00.000-07:00');
$event->setStart($start);
$end = new EventDateTime();
$end->setDateTime('2011-06-03T10:25:00.000-07:00');
$event->setEnd($end);
$attendee1 = new EventAttendee();
$attendee1->setEmail('attendeeEmail');
// ...
$attendees = array($attendee1,
// ...
);
$event->attendees = $attendees;
$createdEvent = $service->events->insert('primary', $event);
echo $createdEvent->getId();
我试过谷歌搜索错误,但我似乎没有找到任何解决方案,你知道我怎么能解决这个问题?
解决方法:
$apiclient->setAccesstoken($_SESSION['oauth_access_token']);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。