이벤트 추가 양식에서 Google 캘린더와 내 일정을 동기화하기위한 데모를 수행하고 있습니다. Google에서 로그인을 완료했지만 Google 캘린더와 동기화 할 수 없습니다. 그 날 401 오류를 제공합니다. 여기 내 코드 도움 당신은 제대로 PHP 클라이언트 라이브러리를 인증하지 않은 감사 :)Google 로그인 후 내 일정을 Google 캘린더와 동기화하는 방법
스케줄러
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script>
function onSignIn(googleUser) {
var profile = googleUser.getBasicProfile();
console.log(profile);
console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead.
console.log('Name: ' + profile.getName());
console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
$('#email').val(profile.getEmail());
}
$('#addScheduler').click(function (e) {
var error = '';
var email=$('#email').val();
var pkShareProfileId=$('#pkShareProfileId').val();
var profileName=$('#profileName').val();
var startDate=$('#startDate').val();
var endDate=$('#endDate').val();
var description=$('#description').val();
$.ajax({
url: 'schedulerAjax.php',
type: 'POST',
data: {'pkShareProfileId': pkShareProfileId, 'profileName':profileName, 'startDate':startDate, 'endDate': endDate, 'description': description, 'email': email},
dataType:'json',
success: showResponse
});
}
</script>
<form method="POST" id="addSchedulerForm" name="addSchedulerForm" enctype="multipart/form-data">
<div class="row">
<p id="errorMsg"></p>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<input type="hidden" id="pkShareProfileId" name="pkShareProfileId">
<input type="hidden" id="email" name="email">
<div class="form-group">
<div class="checkbox g-signin2"data-onsuccess="onSignIn">
Sync With Google Calendar
</div>
</div>
<div class="form-group">
<label for="profileName" class="boxShadowEffect label-basic">Profile Name</label>
<input type="text" class="form-control" id="profileName" placeholder="Profile Name" name="profileName">
</div>
<div class="form-group">
<label for="startDate" class="boxShadowEffect label-basic">Start Date</label>
<input type="text" class="form-control" id="startDate" placeholder="Start Date" name="startDate">
<div class="form-group">
<label for="endDate" class="boxShadowEffect label-basic">End Date</label>
<input type="text" class="form-control" id="endDate" placeholder="End Date" name="endDate">
</div>
</div>
<div class="form-group">
<label for="description" class="boxShadowEffect label-basic">Description</label>
<textarea style="resize:none;" placeholder="Description" id="description" name="description" class="form-control"></textarea>
</div>
<div class="col-xs-10 col-md-12 col-sm-10 col-lg-12">
<input type="button" class="btn hidden-xs btn-primary btn-block btn-flat save" name="addScheduler" value="Save" id="addScheduler" >
</div>
</div>
</div>
</form>
SchedulerAjax.php
require_once __DIR__ . '/vendor/autoload.php';
$client = new Google_Client();
$client->setApplicationName("switchit");
$service = new Google_Service_Calendar($client);
$apiCall = new ApiCall();
if(isset($_POST))
{
$shareProfileId=$_POST['pkShareProfileId'];
$profileName=$_POST['profileName'];
$startDate=$_POST['startDate'];
$startDate=strtotime($startDate);
$endDate=$_POST['endDate'];
$endDate=strtotime($endDate);
$description=$_POST['description'];
$email=$_POST['email'];
if ($email) {
$event = new Google_Service_Calendar_Event(array(
'summary' => $profileName,
'description' => $description,
'start' => array(
'dateTime' => '2017-03-28T00:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
),
'end' => array(
'dateTime' => '2017-03-29T00:00:00-07:00',
'timeZone' => 'America/Los_Angeles',
)
));
$calendarId = 'primary';
$event = $service->events->insert($calendarId, $event);
}
보고있는 정확한 오류는 무엇입니까? – DaImTo
401- 로그인 필요. –
이것을 [mcve]로 만들 수 있다면 도움이 될 것입니다. 그렇지 않으면 읽을 수없는 많은 코드가 있습니다. – dash2