Solved

Error  400 when creating a contact with google api

Posted on 2011-02-22
5
322 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
5 Comments
 
LVL 27

Accepted Solution

by:
BigRat earned 500 total points
Comment Utility
>>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)
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article discusses how to create an extensible mechanism for linked drop downs.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now