I would like to Reverse Geocoding (from GPS coordinates to addresses) and I have a http request from Google Api and is :
$StringaCo= file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?latlng='. $x . ', '.$y.'&sensor=false&location_type=ROOFTOP&result_type=street_address&key=AIzaSyDX7vrxKQI2cHWLS7aghb1ORv1dRX_yQSk');
and I process this http request with :
$StringL= json_decode($StringaCo);
now I want to print all with :
print_r($StringL);
but I received this error :
Warning : file_get_contents(https://maps.googleapis.com/maps/api/geocode/json?latlng=41.805931099999995, 12.432546499999999&sensor=false&location_type=ROOFTOP&result_type=street_address&key=AIzaSyDX7vrxKQI2cHWLS7aghb1ORv1dRX_yQSk): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request.
Could someone, please, help me?
change:
$StringaCo= file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?latlng='.$x.', '.$y.'&sensor=false&location_type=ROOFTOP&result_type=street_address&key=AIzaSyDX7vrxKQI2cHWLS7aghb1ORv1dRX_yQSk');
to:
$StringaCo= file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?latlng='. $x.','.$y.'&sensor=false&location_type=ROOFTOP&result_type=street_address&key=AIzaSyDX7vrxKQI2cHWLS7aghb1ORv1dRX_yQSk');
you need remove extra space after comma
Related
I want to make a http request but i always get
failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
here is my code for the request
$json = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address=Einsteinufer63,10587,Berlin&key=AIzaSyDBA9EWB_zNWC6XjDu9mGyIuuV6QSL_ABM');
var_dump($json);
Here is the modified code i used urlencode() function for address
because if in case you are having space or some special characters in address then google api wont works by the above way
<?php
$json = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode("Einsteinufer63,10587,Berlin").'&key=AIzaSyDBA9EWB_zNWC6XjDu9mGyIuuV6QSL_ABM');
var_dump($json);
?>
I am trying to access multiple json files provided by steam for the market price of an item for CSGO. I am using a first file_get_contents which works:
$inventory = file_get_contents('http://steamcommunity.com/profiles/' . $steamprofile['steamid'] . '/inventory/json/730/2');
but the 2nd onwards doesn't work:
$marketString = file_get_contents('http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=' . urlencode($json_a->{'rgDescriptions'}->$rgDescrId->{'market_hash_name'}));
However I get the error on all items for example:
Warning: file_get_contents(http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Negev%20|%20Nuclear%20Waste%20(Minimal%20Wear)): failed to open stream: HTTP request failed! HTTP/1.0 429 Unknown in /home4/matt500b/public_html/themooliecommunity.com/CSGO/index.php on line 24
I can confirm that allow_url_fopen is on
Pasting the following url into a browser shows that the url works
http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=Negev%20|%20Nuclear%20Waste%20(Minimal%20Wear)
Please note that about 1 hour ago this worked but now throwing an error, any suggestions?
You've got response with status 429 Too many requests
The user has sent too many requests in a given amount of time ("rate
limiting").
So this site can just block too frequent reference to his API
A HTTP 429 is a too many request warning, it's not an error, just a note to tell you you've over done it a little. You'll have to either wait a while or if it's your own server then adjust it's settings to allow for more requests.
I have a php script that will return a google search but it gives me the HTTP error.
if (strstr(file_get_contents("http://www.google.com/search?q=site:http://". $url ."&gws_rd=ssl"), 'did not match any documents.'))
{
return "No";
}
else {
return "Yes";
}
A PHP Error was encountered
Severity: Warning
Message: file_get_contents(http://www.google.com/search?q=site:http://google.com&gws_rd=ssl): failed to open stream: HTTP request failed! HTTP/1.0 503 Service Unavailable
Filename: libraries/google_index.php
Line Number: 8
error : HTTP request failed! HTTP/1.0 503 Service Unavailable.
how can i force this or something so it will get the contents.
If you put an URL as GET parameter of another URL, you must urlencode() it. Otherwise, some characters like ? or & will be considered as parts of the main URL.
Try encoding the whole URL, like:
$string = "google.com/search?q=site:". urlencode($url ."&gws_rd=ssl")
I'm trying to do a composite search in bing search API using php. From this documentation i got this.
https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=%27web%2bnews%27&Query=%27XBox%27&$top=1 This gives some result which i don't know to parse and show the result. I tried `simplexml_load_file()` to parse but no use.
If i mention json format request like below i get a bad request sent error( failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request) and file_get_contents() error
https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=%27web%2bnews%27&?$format=json&Query=%27XBox%27&$top=1
How to get the result with json?
Correct query for you is: (I removed "?" before $format=json)
https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=%27web%2bnews%27&$format=json&Query=%27XBox%27&$top=1
function modify(.......)
{
$mcontact = file_get_contents( "https://test.httpapi.com/api/contacts/modify.json?auth-userid=$uid&auth-password=$pass&contact-id=$cid&name=$name &company=$company&email=$email&address-line-1=$street&city=$city&country=$country&zipcode=$pincode&phone-cc=$countryCodeList[$phc]&phone=$phone" );
$mdetails = json_decode( $mcontact, true );
return $mdetails;
}
using this modify function, displays warning mesage
Warning: file_get_contents(https://...#hihfg.com&address-line-1=3,dfgdf,fgdf&city=dfgfd&country=India&zipcode=641005&phone-cc=91&phone=756657)
[function.file-get-contents]: failed to open stream: HTTP request failed!
HTTP/1.0 400 Bad request in /home/gfdgfd/public_html/new_one/customer/account/class.whois.php
on line 49
Please help me, modify contact details..
HTTP/1.0 400 Bad request - everything you need to know: You are sending a request the server doesn't like.
Are you sure it accepts a GET request and doesn't require POST? Is the URL correct?
Your URL is wrong. You have an additional space character: &name=$name &company=$company. Remove it.