OMG, after everything that i've been through, the problem lies in var_dump($response). I dont know why using var_dump will resend the data. After I change it to print_r everything went as smooth as a butter. Thanks Alain for responding to the question.
Cheers, Adi On Jan 12, 4:06 am, Alain Vongsouvanh <[email protected]> wrote: > Hello, > > The script seems to be fine. What I was suggesting is that the script might > be run twice, maybe the page gets refreshed or re-called and the insertions > are sent again. > You could try adding a random string to the contact's name and printing > this random string to see if the duplicated contacts have the same or not. > > Best, > Alain > > > > > > > > > > On Mon, Jan 9, 2012 at 12:00 PM, justnar <[email protected]> wrote: > > Hi Alain, > > > Thanks for the reply, but I'm quite sure that my script did not run > > twice. Below is my script, could you please point out which part that > > I might do wrong? > > > $document = new DOMDocument('1.0', 'UTF-8'); > > $document->formatOutput = true; > > > $feed = $document->createElement('atom:feed'); > > $feed->setAttributeNS('http://www.w3.org/2000/xmlns/', > > 'xmlns:atom', > > 'http://www.w3.org/2005/Atom'); > > $feed->setAttributeNS('http://www.w3.org/2000/xmlns/', > > 'xmlns:gContact', 'http://schemas.google.com/contact/2008'); > > $feed->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:gd', > > 'http://schemas.google.com/g/2005'); > > $feed->setAttributeNS('http://www.w3.org/2000/xmlns/', > > 'xmlns:batch', > > 'http://schemas.google.com/gdata/batch'); > > > for ($i=0; $i<5; $i++) { > > $entry = $document->createElement('atom:entry'); > > > $entry->appendChild($document->createElement('batch:id', > > $i)); > > > $operation = $document->createElement('batch:operation'); > > $operation->setAttribute('type', 'insert'); > > $entry->appendChild($operation); > > > $category = $document->createElement('category'); > > $category->setAttribute('scheme', ' > >http://schemas.google.com/g/ > > 2005#kind'); > > $category->setAttribute('term', ' > >http://schemas.google.com/g/ > > 2008#contact'); > > $entry->appendChild($category); > > > $name = $document->createElement('gd:name'); > > $fullName = $document->createElement('gd:fullName', 'test > > name'.$i); > > $name->appendChild($fullName); > > $entry->appendChild($name); > > > $homeEmail = $document->createElement('gd:email'); > > $homeEmail->setAttribute('address', 'email'.$ > > [email protected]'); > > $homeEmail->setAttribute('rel' ,' > >http://schemas.google.com/g/ > > 2005#home'); > > $entry->appendChild($homeEmail); > > > $feed->appendChild($entry); > > } > > $document->appendChild($feed); > > > $ch = curl_init(); > > > $header = array(); > > $header[] = "Content-Type: application/atom+xml"; > > $header[] = "GData-Version: 3.0"; > > $header[] = "If-Match: *"; > > $header[] = "Authorization: GoogleLogin auth=".$auth_token; > > > $url = "http://www.google.com/m8/feeds/contacts/default/full/batch > > "; > > > curl_setopt($ch, CURLOPT_TIMEOUT, 150); > > curl_setopt($ch, CURLOPT_URL, $url); > > curl_setopt($ch, CURLOPT_POST, true); > > curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); > > curl_setopt($ch, CURLOPT_HTTPHEADER, $header); > > curl_setopt($ch, CURLOPT_POSTFIELDS, $document->saveXML()); > > > $response = curl_exec($ch); > > > if (curl_errno($ch)) { > > echo curl_error($ch); > > } else { > > var_dump($response); > > } > > > Thanks, > > > Adi > > > On Jan 10, 4:07 am, Alain Vongsouvanh <[email protected]> wrote: > > > Hello, > > > > A silly question, but are you sure you are not running your script twice? > > > That can be the only reason contacts are duplicated. > > > > Best, > > > Alain > > > > On Sat, Jan 7, 2012 at 5:48 AM, justnar <[email protected]> wrote: > > > > Hi all, > > > > > So I have created a script to do batch insert using cURL and PHP. And > > > > everything went smoothly, even I get the response as I want, with the > > > > newly-created google id and etc. The problem is when I log in to the > > > > related google account, I saw that every contacts that I created > > through > > > > batch insert is duplicated and when i try to retrieve it, the > > duplicates > > > > came back with different google id, that is not even mentioned in the > > > > response that i got from previous batch insert process. > > > > > So, is there anyone can help me, or even point me at the right > > direction > > > > on what is wrong with my batch insert process ??? > > > > > -- > > > > You received this message because you are subscribed to the Google > > > > Groups "Google Contacts, Shared Contacts and User Profiles APIs" 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://code.google.com/apis/contacts/community/forum.html > > > > -- > > > Alain Vongsouvanh | Developer Programs Engineer > > > -- > > You received this message because you are subscribed to the Google > > Groups "Google Contacts, Shared Contacts and User Profiles APIs" 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://code.google.com/apis/contacts/community/forum.html > > -- > Alain Vongsouvanh | Developer Programs Engineer -- You received this message because you are subscribed to the Google Groups "Google Contacts, Shared Contacts and User Profiles APIs" 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://code.google.com/apis/contacts/community/forum.html
