Solved

Error  400 when creating a contact with google api

Posted on 2011-02-22
5
347 Views
Last Modified: 2013-11-30
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);
0
Comment
Question by:ercantunc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 27

Accepted Solution

by:
BigRat earned 500 total points
ID: 34971568
>>curl_setopt($ch, CURLOPT_POSTFIELDS, $contactAtom);

You are not posting fields but an XML data stream.

This code snippett should help

http://snippets.dzone.com/posts/show/2596

0
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 39686711
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question