Mac*_*Mac 4 php authentication debugging codeigniter google-calendar-api
正在开发导出并使用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;
}
Run Code Online (Sandbox Code Playgroud)
在进行身份验证后,我会使用我的URL中的选项重定向回我的localhost站点:
http://localhost/project/acp/sync/auth/?code=4/DS91JtSJ5_9Q-Z55Kpyh2AicyWdL
Run Code Online (Sandbox Code Playgroud)
我的脚本将通过检查URI段auth和code查询字符串来检测何时进行了验证- 因此我可以开始将事件导入我的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
Run Code Online (Sandbox Code Playgroud)
这是该代码导入的事件(代码来自谷歌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();
Run Code Online (Sandbox Code Playgroud)
我试过谷歌搜索错误,但我似乎没有找到任何解决方案,你知道我怎么能解决这个问题?
你得到的是401 Login Required因为第二个代码没有设置令牌:
$apiClient->setAccessToken($_SESSION['oauth_access_token']);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9774 次 |
| 最近记录: |