Saturday, 20 September 2014

Add Contacts to Gamil using PHP Curl

Hi Friends I am previously Explan about how to getting google(Gmail) contacts using Google API with php, you can find the process of getting gamil contacts Article here Getting Google Contacts
Now explain about how to add contacts to our gmail account it is very is process through PHP Curl in this process we need "access_token". the following snippet of code is used for add contacts to my gmail account.

   $access_token ='your Access token';
   $contactXML = '<?xml version="1.0" encoding="utf-8"?>
 <atom:entry xmlns:atom="" xmlns:gd="">
 <atom:category scheme="" term=""/>
   <gd:fullName>srinu chilukuri</gd:fullName>
 <gd:email rel="" address="'.$email.'"/>
    <gd:im address=""
 <gd:phoneNumber rel="" primary="true">9999999999</gd:phoneNumber>

   $headers = array(
   'Gdata-version: 3.0',
   'Content-length: '.strlen($contactXML),
   'Content-type: application/atom+xml',
   'Authorization: OAuth '.$access_token

    $contactQuery = '';
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $contactQuery );
   curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $contactXML);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
   curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
   curl_setopt($ch, CURLOPT_TIMEOUT, 400);
   curl_setopt($ch, CURLOPT_FAILONERROR, true);

No comments:

Post a Comment