capturing data for programmatic use in PHP - file_get_contents, curl, both not returning any values

6 posts / 0 new
Last post
virgilr
capturing data for programmatic use in PHP - file_get_contents, curl, both not returning any values

New to the product line and excited!

I have started forming API calls, and am running into difficulty being able to capture the output of the API in PHP.

I am working in a PHP environment.

I have made sure my PHP environment will allow use of file_get_contents.  When using file_get_contents, I receive the following error:failed to open stream: HTTP request failed!

Here is the api url tested with (and yes I did validate the key value as being correct):

http://open.mapquestapi.com/geocoding/v1/batch?key=HIDDEN&callback=renderBatch&json={"locations":[{"street":"Pottsville,PA"},{"street":"Red Lion"},{"street":"19036"},{"street":"1090 N Charlotte St, Lancaster, PA"}]

 

This call does return values when accessed directly in a web browser without issue.

I have also tried using the same url with curl.  I do not receive any errors, but the output is empty.

 

Any php developers here that can give some guidance, it would be greatly appreciated!

 


MQBrianCoakley
The url above is missing an
The url above is missing an ending curly bracket, but even then there should be an error response that the code should be able to read. Sorry, not a php guy so I'd be guessing after that.

virgilr
Good point: the actual url I

Good point: the actual url I am passing (tested) is as follows:

http://open.mapquestapi.com/geocoding/v1/batch?key=HIDDEN&callback=renderBatch&json={"locations":[{"street":"Pottsville,PA"},{"street":"Red Lion"},{"street":"19036"},{"street":"1090 N Charlotte St, Lancaster, PA"}]}


virgilr
Here is another url that was

Here is another url that was generated by my own code.  This is again tested as returning proper values in a browser:

//open.mapquestapi.com/geocoding/v1/batch?key=HIDDEN&callback=renderBatch&json={"locations":[{"street":"910 Providence Highway, Dedham, Massachusetts 02026"},{"street":"700 Grand Concourse,Bronx,New York 10451"}],"options":{"thumbMaps":"false"}}


Thomas.Horacek
Without seeing your PHP code,
Without seeing your PHP code, my first guess would be a lack of url encoding. Maybe post your php function? Another thought, you have the callback parameter specified which is specifically designed for javascript callbacks, it is probably unnecessary for PHP, since it can parse json. 

virgilr
Thomas-

Thomas-

You are dead on.  file_get_contents can't be used, but curl can, after str_replace of spaces to %20.  All is working.

I will remove the callback parameter as you specified- I am now realizing that the documentation provided is for a javascript environment.

Thanks for chiming in- this issue is resolved!