Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a few problems with your code.</p> <p>First, you'd usinre <code>CURLOPT_HTTPHEADERS</code> when in fact, it's <code>CURLOPT_HTTPHEADER</code> (without the trailing "S"). That line should read:</p> <pre><code>curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); </code></pre> <p>Next, Google doesn't want you to pass a parameter name, just a value. The other thing is that the <code>$jsonpost</code> is already JSON so there's no need to call <code>json_encode</code>. The line should read:</p> <pre><code>curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldString); </code></pre> <p>For more information, check the Google documentation: <a href="http://code.google.com/apis/maps/documentation/places/#adding_a_place">http://code.google.com/apis/maps/documentation/places/#adding_a_place</a>.</p> <p><strong>Your complete code, fixed, tested and working:</strong></p> <pre><code>&lt;?php function ProcessCurl($URL, $fieldString){ //Initiate Curl request and send back the result $ch = curl_init(); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($ch, CURLOPT_URL, $URL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_VERBOSE, 1); //curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldString); $resulta = curl_exec ($ch); if (curl_errno($ch)) { print curl_error($ch); } else { curl_close($ch); } echo $resulta; } $jsonpost = '{ "location": { "lat": -33.8669710, "lng": 151.1958750 }, "accuracy": 50, "name": "Daves Test!", "types": ["shoe_store"], "language": "en-AU" }'; $url = "https://maps.googleapis.com/maps/api/place/add/json?sensor=false&amp;key="; $results = ProcessCurl ($url, $jsonpost); echo $results."&lt;BR&gt;"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload