Solved

Error  400 when creating a contact with google api

Posted on 2011-02-22
5
341 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
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

685 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