2017-03-08 118 views
0

我有一個屬性網站,其中列出了多個屬性。每個媒體資源都有一個Google日曆,當該媒體資源在該特定日期進行預訂時,則會在當天爲該特定日曆添加筆記。使用Google API的Google Calendar API的基本示例PHP客戶端

我是手工做這一切,我在那裏通過展示與這樣的佈局可用性更新網站的HTML。

enter image description here

現在我試圖讓這一切都通過谷歌日曆API,我可以像上面的例子日曆顯示每個屬性的預訂自動化。

我嘗試使用谷歌API PHP客戶端庫,其位於https://github.com/google/google-api-php-client

我最大這裏的問題是,我無法找到同樣在互聯網上的任何這基本的例子。 Google網頁未顯示完整示例。

例如,谷歌的引導頁面顯示只是一個「書」,這我並不需要在所有的例子。

我在互聯網上搜索了一些代碼的基本示例,但無法找到它。我搜索stackoverflow本身,但我發現的所有代碼真的很混亂,所有這些都是不同的。

此外,他們中的大多數人已經「知道」它,所以沒有辦法理解需要什麼。

如果有人有一個簡單的例子,我可以拉日曆一天的活動,請張貼在這裏。

另外,如果你知道一些其他的方式來顯示像上面的圖像可用性,將是很大的幫助!

謝謝。

+0

這裏https://developers.google.com/google-apps/calendar/quickstart/php按照文件,如果您有任何錯誤,請告訴我們。 – Morfinismo

+0

看完哥們後回答問題...... –

+0

我做到了。我只是想幫助你。不要指望我們爲你做所有事情,如果你還沒有嘗試過某些東西,並且發佈了你正在使用的代碼。也許這篇文章可以給你一個想法http://stackoverflow.com/questions/42177931/google-calendar-api-get-events-on-current-week。祝你好運! – Morfinismo

回答

1

見鬼,我會重新發佈一個答案,我從this question了:

if($refresh_token_accessed_from_my_database) { 
      //If session contains no valid Access token, get a new one 
      if ($client->isAccessTokenExpired()) { 
       $client->refreshToken($refresh_token_accessed_from_my_database); 
      } 
      //We have access token now, launch the service 
      $this->service = new Google_Service_Calendar($client); 
     } 
     else { 
      //User has never been authorized, so let's ask for the ok 
      if (isset($_GET['code'])) { 
       //Creates refresh and access tokens 
       $credentials = $client->authenticate($_GET['code']); 

       //Store refresh token for further use 
       //I store mine in the DB, I've seen others store it in a file in a secure place on the server 
       $refresh_token = $credentials['refresh_token']; 
       //refresh_token->persist_somewhere() 

       //Store the access token in the session so we can get it after 
       //the callback redirect 
       $_SESSION['access_token'] = $client->getAccessToken(); 
       $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 
       header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL)); 
      } 

      if (!isset($_SESSION['access_token'])) { 
       $auth_url = $client->createAuthUrl(); 
       header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL)); 
      } 

      if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { 
       $client->setAccessToken($_SESSION['access_token']); 
       $this->service = new Google_Service_Calendar($client); 
      } 

當我建立了我的項目,我從教程Morfinismo後在評論中開始,但我有一對夫婦的問題,以下那個。我已經發表了評論來描述一般流程和一些潛在的問題點,如果您對發生的事情不太清楚,您可能希望將這些說明與其他教程進行比較。