{"id":1759,"date":"2012-09-10T13:17:41","date_gmt":"2012-09-10T09:17:41","guid":{"rendered":"http:\/\/www.dhtmlx.com\/blog\/?p=1759"},"modified":"2023-05-05T14:10:18","modified_gmt":"2023-05-05T11:10:18","slug":"dhtmlxscheduler-synchronization-with-google-calendar","status":"publish","type":"post","link":"https:\/\/dhtmlx.com\/blog\/dhtmlxscheduler-synchronization-with-google-calendar\/","title":{"rendered":"How to Synchronize dhtmlxScheduler with Google Calendar"},"content":{"rendered":"<p><strong>Update: The proxy script for synchronization with Google Calendar has been updated to work correctly with Google API v.3. <a href=\"https:\/\/github.com\/DHTMLX\/scheduler-google-calendar\">Download it from GitHub<\/a>.<\/strong><\/p>\n<p>Today we want to show you an effortless way to synchronize <a href=\"https:\/\/dhtmlx.com\/docs\/products\/dhtmlxScheduler\/\">dhtmlxScheduler<\/a> and Google Calendar. So if you need to store your events and appointments in both calendars, you won&#8217;t miss any appointed event ever.<\/p>\n<p>Google Calendar is one of the most popular online web calendars and that&#8217;s why it&#8217;s so essential to give developers a quick and simple way to synchronize dhtmlxScheduler with it. The synchronization feature has been available before, but now it became really easy. <\/p>\n<p>The technique of synchronization is pretty simple and based on using a PHP proxy script: <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2012\/09\/google_calendar_sync.png\" alt=\"Synchronization with Google Calendar\" title=\"Synchronization with Google Calendar\" width=\"600\" height=\"153\" class=\"aligncenter size-full wp-image-1760\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2012\/09\/google_calendar_sync.png 600w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2012\/09\/google_calendar_sync-300x76.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>The synchronization script works as a simple proxy between a client-side application (containing dhtmlxScheduler)  and Google Calendar. To load events, the scheduler makes a call to the proxy script, which  in its turn, makes a call to Google Calendar API. Retrieved data is converted to the scheduler format and loaded to the client side.<\/p>\n<p><!--more-->&nbsp;<\/p>\n<h2>One-Way Synchronization<\/h2>\n<p>&nbsp;<br \/>\nTo start synchronization, check whether the <strong>php_curl.dll<\/strong> extension is enabled. If it&#8217;s not, activate it by adding the following line in the <strong>php.ini<\/strong> file used by your web server:<\/p>\n<div class=\"codecolorer-container php default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"php codecolorer\">extension<span class=\"sy0\">=<\/span>php_curl<span class=\"sy0\">.<\/span>dll<\/div><\/div>\n<p>To provide one-way synchronization that will allow you to automatically fetch data from Google Calendar to dhtmlxScheduler, do the following:<\/p>\n<p><strong>1. <\/strong>Download the <a href=\"https:\/\/dhtmlx.com\/x\/download\/regular\/gCal_proxy_v2.zip\">gCal_proxy_v2 package<\/a>.<\/p>\n<p><strong>2. <\/strong>Unzip the package into the root directory of your web server.<\/p>\n<p><strong>3.<\/strong> Open the <strong>01_proxy.php<\/strong> file located at [rootFolder]\\gCal_proxy\\server\\ . The file contains the standard proxy initialization code:<\/p>\n<div class=\"codecolorer-container php default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"php codecolorer\"><span class=\"kw2\">&lt;?php<\/span><br \/>\n&nbsp;<br \/>\n<span class=\"re0\">$email<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"re0\">$pass<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"re0\">$cal<\/span> <span class=\"sy0\">=<\/span> <span class=\"st0\">&quot;&quot;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp;<br \/>\n<span class=\"kw1\">include<\/span><span class=\"br0\">&#40;<\/span><span class=\"st_h\">'google_proxy.php'<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"re0\">$calendar<\/span> <span class=\"sy0\">=<\/span> <span class=\"kw2\">new<\/span> GoogleCalendarProxy<span class=\"br0\">&#40;<\/span><span class=\"re0\">$email<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">$pass<\/span><span class=\"sy0\">,<\/span> <span class=\"re0\">$cal<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"re0\">$calendar<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">connect<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n&nbsp;<br \/>\n<span class=\"sy1\">?&gt;<\/span><\/div><\/div>\n<p><strong>NOTE:<\/strong> For Google API v.3 the code should be different:<\/p>\n<div class=\"codecolorer-container php default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"php codecolorer\"><span class=\"kw2\">&lt;?php<\/span><br \/>\n<br \/>\n<span class=\"kw1\">include<\/span><span class=\"br0\">&#40;<\/span><span class=\"st_h\">'..\/src\/google_proxy.php'<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<span class=\"re0\">$calendar<\/span> <span class=\"sy0\">=<\/span> <span class=\"kw2\">new<\/span> GoogleCalendarProxy<span class=\"br0\">&#40;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"st0\">&quot;&lt;account&gt;@developer.gserviceaccount.com&quot;<\/span><span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; <span class=\"st0\">&quot;&lt;account&gt;.apps.googleusercontent.com&quot;<\/span><span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw3\">file_get_contents<\/span><span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;&lt;key&gt;&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">,<\/span><br \/>\n&nbsp; &nbsp; <span class=\"st0\">&quot;&lt;calendar id&gt;&quot;<\/span><br \/>\n<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<br \/>\n<span class=\"re0\">$calendar<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"me1\">connect<\/span><span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\n<span class=\"sy1\">?&gt;<\/span><\/div><\/div>\n<p><strong>4.<\/strong> Set values for the following 3 variables and leave the rest of the code as is:<\/p>\n<ul>\n<li><strong>$email<\/strong> &#8211; the user name of your Gmail account<\/li>\n<li><strong>$pass<\/strong> &#8211; the password of your Gmail account<\/li>\n<li><strong>$cal<\/strong> &#8211; the name of your Google Calendar<\/li>\n<\/ul>\n<p>&nbsp;<br \/>\nNOTE: Be sure to provide the correct values. For example, if the name of your calendar is test@googlemail.com,  the value test@gmail.com will result in an error.<\/p>\n<p>After that, all events from your Google Calendar will be reflected in dhtmlxScheduler. When you add or edit an event in Google Calendar, these changes will appear in dhtmlxScheduler when the page is refreshed. <\/p>\n<p>&nbsp;<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2012\/09\/google_calendar_sync1.png\" alt=\"Synchronization between Google Calendar and dhtmlxScheduler\" title=\"Synchronization between Google Calendar and dhtmlxScheduler\" width=\"606\" height=\"440\" class=\"aligncenter size-full wp-image-1768\" srcset=\"https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2012\/09\/google_calendar_sync1.png 606w, https:\/\/dhtmlx.com\/blog\/wp-content\/uploads\/2012\/09\/google_calendar_sync1-300x217.png 300w\" sizes=\"auto, (max-width: 606px) 100vw, 606px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>Two-Way Synchronization between Google Calendar and dhtmlxScheduler<\/h2>\n<p>&nbsp;<br \/>\nYou can also add two-way synchronization and integrate dhtmlxScheduler with Google Calendar so you can edit your events and appointments in either calendar, and the other stays up-to-date. This will require some &#8216;magic&#8217; on the client-side page.<\/p>\n<p><strong>1.<\/strong> Open the HTML file that contains the initialization code for the scheduler. In the load() method, specify the path to the <strong>01_proxy.php<\/strong> file (that includes your Google Calendar info) &#8211; it will replace the data file that you used to load events from.<\/p>\n<div class=\"codecolorer-container php default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"php codecolorer\">scheduler<span class=\"sy0\">.<\/span>load<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;..\/gCal_proxy\/server\/01_proxy.php&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><\/div><\/div>\n<p><strong>2.<\/strong> Initialize dataProcessor (if you haven&#8217;t done it before) and specify the path to the same PHP file <strong>01_proxy.php<\/strong> as a parameter of the constructor.<\/p>\n<div class=\"codecolorer-container javascript default codecolorer-noborder\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"javascript codecolorer\"><span class=\"sy0\">&lt;<\/span>script src<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;..\/gCal_proxy\/sample\/codebase\/dhtmlxdataprocessor.js&quot;<\/span> type<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;text\/javascript&quot;<\/span> charset<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;utf-8&quot;<\/span><span class=\"sy0\">&gt;&lt;\/<\/span>script<span class=\"sy0\">&gt;<\/span><br \/>\n...<br \/>\n<span class=\"kw1\">var<\/span> dp <span class=\"sy0\">=<\/span> &nbsp;<span class=\"kw1\">new<\/span> dataProcessor<span class=\"br0\">&#40;<\/span><span class=\"st0\">&quot;..\/gCal_proxy\/server\/01_proxy.php&quot;<\/span><span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span><br \/>\ndp.<span class=\"me1\">init<\/span><span class=\"br0\">&#40;<\/span>scheduler<span class=\"br0\">&#41;<\/span><span class=\"sy0\">;<\/span> <span class=\"co1\">\/\/ 'scheduler' is the name of the scheduler instance<\/span><\/div><\/div>\n<p>The two-way synchronization is ready, and now changes you make in dhtmlxScheduler or Google Calendar will be synchronized between these two calendars. To see the changes, you need to refresh the page. Note that it took us less than 10 minutes to integrate dhtmlxScheduler with Google Calendar. Pretty good result, huh?<\/p>\n<p>For more details on this topic, refer to our <a href=\"https:\/\/docs.dhtmlx.com\/scheduler\/synchronization_with_google_calendar.html\" target=\"_blank\">documentation<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Update: The proxy script for synchronization with Google Calendar has been updated to work correctly with Google API v.3. Download it from GitHub. Today we want to show you &#8230;<\/p>\n","protected":false},"author":2,"featured_media":3354,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,71,1],"tags":[33,14,15],"class_list":["post-1759","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-posts-for-codeproject-com","category-tutorials","category-uncategorized","tag-all-posts","tag-tips","tag-dhtmlxscheduler"],"_links":{"self":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/1759","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/comments?post=1759"}],"version-history":[{"count":1,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/1759\/revisions"}],"predecessor-version":[{"id":10845,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/posts\/1759\/revisions\/10845"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media\/3354"}],"wp:attachment":[{"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/media?parent=1759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/categories?post=1759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dhtmlx.com\/blog\/wp-json\/wp\/v2\/tags?post=1759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}