I am trying to create Google Contact using php
but contacts get added into ( Other Contacts ) I want to Programmatically add it to Contacts Tab
because while syncing the contact it does not sync (other contacts) so i manually has to add it from other to contact from sync in mobile phone
$contactXML = '<?xml version="1.0" encoding="utf-8"?> '
. '<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005">'
. ' <atom:category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/contact/2008#contact"/> '
. '<gd:name> <gd:givenName>' . $id1 . '</gd:givenName> <gd:fullName></gd:fullName> <gd:familyName>' . $id3 . '</gd:familyName>'
. ' </gd:name> <gd:email rel="http://schemas.google.com/g/2005#home" address="' . $id2 . '"/> '
. '<gd:im address="'. $id2 .'" protocol="http://schemas.google.com/g/2005#GOOGLE_TALK" primary="true" rel="http://schemas.google.com/g/2005#home"/>'
. ' <gd:phoneNumber rel="http://schemas.google.com/g/2005#home" primary="true">' . $id4 . '</gd:phoneNumber> </atom:entry>';
$headers = array(
'Host: www.google.com',
'Gdata-version: 3.0',
'Content-length: ' . strlen($contactXML),
'Content-type: application/atom+xml',
'Authorization: OAuth ' . $accesstoken);
$contactQuery = 'https://www.google.com/m8/feeds/contacts/default/full/';
$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);
$result = curl_exec($ch);
$xml = simplexml_load_string($result);
My Answer:
Rate this post
5 of 5 based on 3575 votesComments