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

相关问题