ercantunc
asked on
Error 400 when creating a contact with google api
This code returns 400 error Response contains no content type
Any ideas?
function create($url, $token)
{
$contactAtom = new DOMDocument();
$contactAtom->formatOutput = true; $topLevel = $contactAtom->createElemen t('atom:en try');
$topLevel->setAttribute('x mlns:atom' , 'http://www.w3.org/2005/Atom');
$topLevel->setAttribute('x mlns:gd', 'http://schemas.google.com/g/2005');
$contactAtom->appendChild( $topLevel) ;
$category = $contactAtom->createElemen t('atom:ca tegory');
$category->setAttribute('s cheme', 'http://schemas.google.com/g/2005#kind');
$category->setAttribute('t erm', 'http://schemas.google.com/contact/2008#contact');
$topLevel->appendChild($ca tegory);
$name = $contactAtom->createElemen t('gd:name ');
$givenName = $contactAtom->createElemen t('gd:give nName', "Elizabeth");
$familyName = $contactAtom->createElemen t('gd:fami lyName', "Bennett");
$fullName = $contactAtom->createElemen t('gd:full Name', "Elizabeth Bennett");
$name->appendChild($givenN ame);
$name->appendChild($family Name);
$name->appendChild($fullNa me);
$topLevel->appendChild($na me);
print $contactAtom->saveXML();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $contactAtom);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curlheader[0] = sprintf("Authorization: AuthSub token=\"%s\"/n GData-Version:\"3.0\" ", $token);
$curlheader[1] = 'Content-Type: application/atom+xml';
curl_setopt($ch, CURLOPT_HTTPHEADER, $curlheader);
curl_setopt($ch, CURLOPT_HEADER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
$sXML =create('https://www.google.com/m8/feeds/contacts/default/full',$tokd);
print_r ($sXML);
Any ideas?
function create($url, $token)
{
$contactAtom = new DOMDocument();
$contactAtom->formatOutput
$topLevel->setAttribute('x
$topLevel->setAttribute('x
$contactAtom->appendChild(
$category = $contactAtom->createElemen
$category->setAttribute('s
$category->setAttribute('t
$topLevel->appendChild($ca
$name = $contactAtom->createElemen
$givenName = $contactAtom->createElemen
$familyName = $contactAtom->createElemen
$fullName = $contactAtom->createElemen
$name->appendChild($givenN
$name->appendChild($family
$name->appendChild($fullNa
$topLevel->appendChild($na
print $contactAtom->saveXML();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $contactAtom);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$curlheader[0] = sprintf("Authorization: AuthSub token=\"%s\"/n GData-Version:\"3.0\" ", $token);
$curlheader[1] = 'Content-Type: application/atom+xml';
curl_setopt($ch, CURLOPT_HTTPHEADER, $curlheader);
curl_setopt($ch, CURLOPT_HEADER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
$sXML =create('https://www.google.com/m8/feeds/contacts/default/full',$tokd);
print_r ($sXML);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.