Link to home
Start Free TrialLog in
Avatar of ercantunc
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->createElement('atom:entry');
    $topLevel->setAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom');
    $topLevel->setAttribute('xmlns:gd', 'http://schemas.google.com/g/2005');
  $contactAtom->appendChild($topLevel);  
  $category =  $contactAtom->createElement('atom:category');
    $category->setAttribute('scheme', 'http://schemas.google.com/g/2005#kind');
    $category->setAttribute('term', 'http://schemas.google.com/contact/2008#contact');
  $topLevel->appendChild($category);
  $name = $contactAtom->createElement('gd:name');
    $givenName = $contactAtom->createElement('gd:givenName', "Elizabeth");
    $familyName = $contactAtom->createElement('gd:familyName', "Bennett");
    $fullName = $contactAtom->createElement('gd:fullName', "Elizabeth Bennett");
    $name->appendChild($givenName);
    $name->appendChild($familyName);
    $name->appendChild($fullName);
  $topLevel->appendChild($name);  
 
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
Avatar of BigRat
BigRat
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.