简体   繁体   中英

How to write events on outlook calendars using php rest scope?

I can read all my hotmail calendar events and contacts using oauth live connect.

Below is the login url

$urls = https://login.live.com/oauth20_authorize.srf?client_id='.$auth['client_id'].'&scope=wl.signin%20wl.basic%20wl.emails%20wl.contacts_emails%20wl.contacts_calendars%20wl.calendars_update&response_type=code&redirect_uri='.$app_path;

After successful login I can get all my hotmail calendar events and contacts using the accesstoken

url = 'https://apis.live.net/v5.0/me/contacts?access_token='.$accesstoken;
url = 'https://apis.live.net/v5.0/me/events?access_token='.$accesstoken;    
response =  file_get_contents($url);
$response = json_decode($response, true);   

Events are listing in jquery fullcalendar . Also I can add events in my jquery fullcalendar with fields subject,start_date,end_date and description etc

在此输入图像描述

Following link only i used for reference.

https://msdn.microsoft.com/en-IN/library/hh826523.aspx#cal_rest

$('#calendar').fullCalendar({
header: {
  left: 'prev,next today',
  center: 'title',
  right: 'month,agendaWeek,agendaDay'
},
defaultDate: '2015-12-01',
editable: true,
events: _events,  
dayClick: function(date, allDay, jsEvent, view) {
   $('#fullCalModal').modal();
                   $.ajax({
                    url: AJAX_PATH + "/user/create_event",
                    type: 'POST',
                    data: $form.serialize(),
                    dataType: 'json',
                    success: function(result) {
                        if(result.status == "success"){
                         window.location =  result.redirect;
                        }else{                  
                            alert("error...");
                        }
                    }
                });
}
});

create_event function

 $url = "https://apis.live.net/v5.0/me/events";
                $fuseau = date("P"); 
                $titre = "Hello"; 
                $description = "Welcome to our world";
                $data_json = '{   "Subject": "' . $titre . '",
                                  "start_time": "2015-12-22T01:30:00-11:00",
                                  "end_time": "2015-12-22T03:00:00-11:00",
                                  "location": "Coho Vineyard and Winery, 123 Main St., Redmond WA 19532",
                                  "is_all_day_event": false,
                                  "availability": "busy",
                                  "visibility": "public"                    
                                }';

                $options = array("http" => array(   "method" => "POST",
                                                    "header" => "Authorization: Bearer $accesstoken \r\n" .
                                                                "Content-type: application/json\r\n",
                                                    "content" => $data_json                                         
                                                    ));



                $context = stream_context_create($options);  

but event is not getting created in live server.

please do help me.

Yes, I got the answer . Using cURL method event is posted to outlook server

$url = "https://apis.live.net/v5.0/me/events";                   
                $data_json = '{
                    "name": "'.$subject.'",
                    "description": "'.$description.'",
                    "start_time": "'.$new_start_date_time.':00+530",
                    "end_time": "'.$new_end_date_time.':00+530",
                    "location": "'.$location.'",
                    "is_all_day_event": true,
                    "availability": "busy",
                    "visibility": "public"
                }';
             //print_r($data_json);die;
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json); 
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            "Content-Type: application/json",
            "Authorization: Bearer " . $accesstoken, 
            "Content-length: ".strlen($data_json))
            );
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             $result = curl_exec($ch);  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM