Hi!
This code works fine when adding one contact. But I wanted to take all
the records from the table contacts. The loop however executes for 20
to 40 records with random number. It does not insert all the contacts.
sometimes 20 and sometimes around 40 in the gmail account. The
condition for 200 is set so that records does not exceed 200. I think
there is a condition check in the api for 200 contacts. Any idea what
is the problem
<?php
// load Zend Gdata libraries
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Http_Client');
Zend_Loader::loadClass('Zend_Gdata_Query');
Zend_Loader::loadClass('Zend_Gdata_Feed');
// set credentials for ClientLogin authentication
$user = "[email protected]";
$pass = "pass";
try {
// perform login and set protocol version to 3.0
$client = Zend_Gdata_ClientLogin::getHttpClient(
$user, $pass, 'cp');
$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
$link = mysql_connect('localhost', 'root', 'root');
mysql_select_db("database");
$sql="select * from contacts";
$res=mysql_query($sql);
$rs=mysql_fetch_assoc($res);
$i=1;
do{
if($i<200)
{
echo "number".$rs['index']." ".$rs['Name'];
// create new entry
$doc = new DOMDocument();
$doc->formatOutput = true;
$entry = $doc->createElement('atom:entry');
$entry->setAttributeNS('http://www.w3.org/2000/xmlns/' ,
'xmlns:atom', 'http://www.w3.org/2005/Atom');
$entry->setAttributeNS('http://www.w3.org/2000/xmlns/' ,
'xmlns:gd', 'http://schemas.google.com/g/2005');
$doc->appendChild($entry);
// add name element
$name = $doc->createElement('gd:name');
$entry->appendChild($name);
$name1=$rs['Name'];
$fullName = $doc->createElement('gd:fullName', $name1);
$name->appendChild($fullName);
// add email element
$email = $doc->createElement('gd:email');
$email1=$rs['E-Mail'];
if(empty($email1))
$email1="[email protected]";
$email->setAttribute('address' ,$email1);
$email->setAttribute('rel' ,'http://schemas.google.com/g/
2005#home');
$entry->appendChild($email);
// add org name element
$org = $doc->createElement('gd:organization');
$org->setAttribute('rel' ,'http://schemas.google.com/g/2005#work');
$entry->appendChild($org);
$phone=$rs['Phone'];
$orgName = $doc->createElement('gd:orgName', $phone);
$org->appendChild($orgName);
// add org name element
$Phone = $doc->createElement('gd:Phone');
$Phone->setAttribute('rel' ,'http://schemas.google.com/g/
2005#work');
$entry->appendChild($Phone);
$phone1=$rs['Phone'];
$PhoneName = $doc->createElement('gd:PhoneName', $phone1);
$Phone->appendChild($PhoneName);
// insert entry
$entryResult = $gdata->insertEntry($doc->saveXML(),
'http://www.google.com/m8/feeds/contacts/default/full');
echo '<h2>Add Contact</h2>';
echo 'The ID of the new entry is: ' . $i;
}
$i++;
}while($rs=mysql_fetch_assoc($res));
} catch (Exception $e) {
die('ERROR:' . $e->getMessage());
}
?>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Contacts API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-contacts-api?hl=en
-~----------~----~----~----~------~----~------~--~---