0

我正在PHP中開發一個web應用程序來預約約會。我有fullcalendar,它工作正常。我還需要直接在我的Google日曆上保存活動。可能嗎?php腳本在google日曆上設置事件

在谷歌API我發現只有「如何添加事件的用戶日曆」,而不是我的日曆。

+1

如果你想在所有情況下保存到一個特定的谷歌日曆,沒有最終用戶不得不登錄,那麼你需要做那個服務器端。讓您的日曆頁面將有關新約會的數據發送到您的服務器(通過ajax或其他),然後使用PHP連接到Google Calendar API並將數據發送給Google。使用服務帳戶進行身份驗證。 Google提供了一個PHP客戶端庫來幫助你解決這個問題,以及大量的文檔和示例。 – ADyson

回答

0

如果您使用服務帳戶,則可以通過授予您的日曆的服務帳戶權限,直接保存到自己的日曆中。

require_once __DIR__ . '/vendor/autoload.php'; 
// Use the developers console and download your service account 
// credentials in JSON format. Place the file in this directory or 
// change the key file location if necessary. 
putenv('GOOGLE_APPLICATION_CREDENTIALS='.__DIR__.'/service-account.json'); 
/** 
* Gets the Google client refreshing auth if needed. 
* Documentation: https://developers.google.com/identity/protocols/OAuth2ServiceAccount 
* Initializes a client object. 
* @return A google client object. 
*/ 
function getGoogleClient() { 
    return getServiceAccountClient(); 
} 
/** 
* Builds the Google client object. 
* Documentation: https://developers.google.com/api-client-library/php/auth/service-accounts 
* Scopes will need to be changed depending upon the API's being accessed. 
* array(Google_Service_Analytics::ANALYTICS_READONLY, Google_Service_Analytics::ANALYTICS) 
* List of Google Scopes: https://developers.google.com/identity/protocols/googlescopes 
* @return A google client object. 
*/ 
function getServiceAccountClient() { 
    try { 
     // Create and configure a new client object.   
     $client = new Google_Client(); 
     $client->useApplicationDefaultCredentials(); 
     $client->addScope([YOUR SCOPES HERE]); 
     return $client; 
    } catch (Exception $e) { 
     print "An error occurred: " . $e->getMessage(); 
    } 
} 

代碼從我php sample project for Google calendar如果你有興趣在這裏是如何服務賬戶的工作,以及如何建立一個帳戶的文章撕開。 Google development for beginners service accounts

相關問題