1

이벤트 추가 양식에서 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); 
} 
+0

보고있는 정확한 오류는 무엇입니까? – DaImTo

+0

401- 로그인 필요. –

+0

이것을 [mcve]로 만들 수 있다면 도움이 될 것입니다. 그렇지 않으면 읽을 수없는 많은 코드가 있습니다. – dash2

답변

0

감사 할 것입니다 제발 나 좀 도와. 그래서 당신이하려는 일을 할 수있는 권한이 없습니다.

$client = new Google_Client(); 
$client->setApplicationName(APPLICATION_NAME); 
$client->setScopes(SCOPES); 
$client->setAuthConfig(CLIENT_SECRET_PATH); 
$client->setAccessType('offline'); 

당신은 Calendar PHP quickstart tutorial를 확인하려고 할 수 있습니다.

Google 로그인 (클라이언트 로그인)과 PHP (서버 쪽) 로그인을 연결할 수 있는지 전혀 알 수 없습니다. 나는 그것을 심각하게 의심한다. PHP를 삭제하고 자바 스크립트 만 사용하는 것이 좋습니다. JavaScript quick start

+0

이 CLIENT_SECRET_PATH에 대해 잘 알지 못해서 제게 이것을 기쁘게 해드릴 수 있습니까? –

+0

로긴 구글 계정 캘린더에 내 이벤트를 추가 할 수 있도록 로그인하려고합니다. –

+0

튜토리얼을 따라 간다면 https://developers.google.com/google-apps/calendar/quickstart/php에 링크되어 있습니다. 모든 설정 방법은 Google에서 안내합니다. – DaImTo