Jump to content

M_cMoreland

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

M_cMoreland's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. OK I am a bit of newb so forgive me. However I am trying to create a page that I can send an ID to and display the JSON of a url this page builds a new url (for another domain) I want to display the JSON from the new url. CODE: <?php //Get Client IP and Set $client_ip //if ( isset($_SERVER["REMOTE_ADDR"]) ) { //$client_ip=$_SERVER["REMOTE_ADDR"]; //} else if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ) { //$client_ip=$_SERVER["HTTP_X_FORWARDED_FOR"]; //} else if ( isset($_SERVER["HTTP_CLIENT_IP"]) ) { //$client_ip=$_SERVER["HTTP_CLIENT_IP"]; //} //Get listing ID from URL filter_input(INPUT_GET, 'listing_id', FILTER_SANITIZE_STRING); $listing_id = '10100230'; $client_ip = '123.4.56.78'; //Set Static Variables $publisher = 'test'; $format = 'JSON'; $placement = 'xpage'; //Create query_string array for URL $query_string = array('listing_id' => $listing_id, 'placement' => $placement, 'client_ip' => $client_ip, 'publisher' => $publisher, 'format' => $format ); //Build url $url = "http://api.citygridmedia.com/content/places/v2/detail?" . http_build_query($query_string, '', "&"); print $url ?> Right now it works to build the url what do I need to do to pull the json from the new URL and display it in the same or another page? Here is the URL that is built and it works in a browser. http://api.citygridmedia.com/content/places/v2/detail?listing_id=10100230&placement=test_page&client_ip=123.4.56.78&publisher=test&format=JSON MOD EDIT: code tags added.
  2. I double checked Curl was working on the server.. and it appears to be working just fine.. http://go.followclix.com/bing/curltest.php <? //Three parts to the querystring: q is address, output is the format, key is the GAPI key $key = "x"; $address = urlencode("columbia MO"); //If you want an extended data set, change the output to "xml" instead of csv $url = "http://maps.google.com/maps/geo?q=".$address."&output=csv&key=".$key; //Set up a CURL request, telling it not to spit back headers, and to throw out a user agent. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER,0); //Change this to a 1 to return headers curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); echo "Data: ". $data; ?>
  3. OK I am getting the following error syntax error, unexpected T_VARIABLE on line 27 which is $request = curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); Any thoughts?
  4. OK would it be something like this .... // Call custom function to generate an HTTP request and get back an HTTP response $response = do_post_request($url, $data); // This function constructs and sends an HTTP request with a provided URL and data, and returns an HTTP response object // This function uses the php_http extension function do_post_request($url, $data, $optional_headers = null) { $ch = curl_intit(); $request = curl_setop($ch, CURLOPT_URL, $url); $request = curl_setop($ch, CURLOPT_HEADER,0) $request = curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); $request = curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $request = curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $request = $data = curl_exec($ch); $response =$request->send(); return $response->getBody(); curl_close($ch) }
  5. OK .. I know this should be really easy.. but refer to the I am a noob comment before.. here is my full page I am just a little confused on how to put Curl in place .. this is really just my lack of coding experience.. ask me about a Cisco router and I ll be great help--lol -- anyway I am trying to upload and utilize the Bing Spatial Data to post a xml file so I can attach some custom items to an entity.. <html> <head> <title>Using the Bing Spatial Data Geocode Dataflow API</title> </head> <body> <?php $key = "xxxxxxx"; $url = "http://spatial.virtualearth.net/REST/v1/Dataflows/Geocode?description=MyJob&input=xml&output=xml&key=".$key; // STEP 1 - Create a geocode job // Get the contents of an XML data file $myfile = "geocodefeed.xml"; $data = file_get_contents($myfile); // Call custom function to generate an HTTP request and get back an HTTP response $response = do_post_request($url, $data); // This function constructs and sends an HTTP request with a provided URL and data, and returns an HTTP response object // This function uses the php_http extension function do_post_request($url, $data, $optional_headers = null) { $request = new HttpRequest($url, HttpRequest::METH_POST); $request->setBody($data); $response = $request->send(); return $response->getBody(); } // Convert the response body into an XML element so we can extract data $responseBody = new SimpleXMLElement($response); // Get data (such as job id, status description, and job status) from the response $statusDescription = $responseBody->StatusDescription; $jobId = $responseBody->ResourceSets->ResourceSet->Resources->DataflowJob->Id; $jobStatus = $responseBody->ResourceSets->ResourceSet->Resources->DataflowJob->Status; echo "Job Created:<br>"; echo " Request Status: ".$statusDescription."<br>"; echo " Job ID: ".$jobId."<br>"; echo " Job Status: ".$jobStatus."<br><br>"; // STEP 2 - Get the status of geocode job(s) // Call the API to determine the status of all geocode jobs associated with a Bing Maps key echo "Checking status until complete...<br>"; while ($jobStatus != "Completed") { // Wait 5 seconds, then check the job’s status sleep(5); // Construct the URL to check the job status, including the jobId $checkUrl = "http://spatial.virtualearth.net/REST/v1/Dataflows/Geocode/".$jobId."?output=xml&key=".$key; $checkResponse = file_get_contents($checkUrl); $responseBody = new SimpleXMLElement($checkResponse); // Get and print the description and current status of the job $jobDesc = $responseBody->ResourceSets->ResourceSet->Resources->DataflowJob->Description; $jobStatus = $responseBody->ResourceSets->ResourceSet->Resources->DataflowJob->Status; echo $jobDesc." - ".$jobStatus."<br>"; } // STEP 3 - Obtain results from a successfully geocoded set of data //Iterate through the links provided with the first geocode job and extract the 'succeeded' link $Links = $responseBody->ResourceSets->ResourceSet->Resources->DataflowJob->Link; foreach ($Links as $Link) { if ($Link['name'] == "succeeded") { $successUrl = $Link; break; } } // Access the URL for the successful requests, and convert response to an XML element $successUrl .= "?output=xml&key=".$key; $successResponse = file_get_contents($successUrl); $successResponseBody = new SimpleXMLElement($successResponse); // Loop through the geocoded results and output addresses and lat/long coordinates foreach ($successResponseBody->GeocodeEntity as $entity) { echo $entity->GeocodeResponse->Address['FormattedAddress'],"<br>"; if (!$entity->GeocodeResponse->RooftopLocation) { echo $entity->GeocodeResponse->InterpolatedLocation['Longitude'].", "; echo $entity->GeocodeResponse->InterpolatedLocation['Latitude']."<br>"; } else { echo $entity->GeocodeResponse->RooftopLocation['Longitude'].", "; echo $entity->GeocodeResponse->RooftopLocation['Latitude']."<br>"; } } ?> </body> </html>
  6. All I have this snippet of code I want to convert to CURL.. I am a bit of a newbie on this so any help is greatly appreciated. $response = do_post_request($url, $data); // This function constructs and sends an HTTP request with a provided URL and data, and returns an HTTP response object // This function uses the php_http extension function do_post_request($url, $data, $optional_headers = null) { $request = new HttpRequest($url, HttpRequest::METH_POST); $request->setBody($data); $response = $request->send(); return $response->getBody(); } // Convert the response body into an XML element so we can extract data $responseBody = new SimpleXMLElement($response);
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.