I am trying to create a simple script that will retrieve the last 5 feeds for a twitter user (in this instance the BBC)
It runs okay locally on my development server but once I upload this to a live site I get the following error:
Warning: file_get_contents(https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=bbc&count=5): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in ....
Does anyone know why this doesn't work on my live server (but fine on my dev server?)
As mentioned in file_get_contents throws 400 Bad Request error PHP, you may be better using curl instead of file_get_contents due to its improved error handling - this may provide you with another clue.
Related
i am trying to create a PNG resource from an image on a remote server, for that i use
$im = imageCreateFromPng('http://textures.minecraft.net/texture/7235ea086a4604e15e513c4add3935d64f23c535f9f62917c6d4886705ac8cf');
but when i execute the script it gives me this error:
Warning: imagecreatefrompng(*url*): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
I tried to access the url above with my browser and the image loaded just fine, then i made a head request to that URL to see if the server sends a 404 header but i found out that it does not. so i have no idea how to solve this issue, thank you for reading.
EDIT
everything works just fine on another server i own, just not this one.
Hi I would like to ask why i get this ERROR
I am using file_get_contents()
and I am currently receiving an ERROR
failed to open stream: HTTP request failed!
I would like to know how to prevent this.
I also search about curl and it is better than what I'm using right now its not matter for me if I re code or not. What i want to know is the factors why I am receiving this ERROR.
I have done searching but still i don't have clear view with this. Any comments and knowledge is well appreciated.Thanks!
i am trying to write a very simple php script to test if host api.twitter.com is up. but when i do
file_get_contents('https://api.twitter.com')
then i get the error
Warning: file_get_contents(https://api.twitter.com):
failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found
a simple ping on the command line works fine, and file_get_contents works fine on other urls, eg http://google.com.
before i give curl a try i thought i would see if i am doing something wrong with file_get_contents()?
https://api.twitter.com on its own does actually return a 404 - its normal. If you're wanting to interact with the API you have to use something like:
https://api.twitter.com/1.1/statuses/mentions_timeline.json
Documentation: https://dev.twitter.com/docs/api/1.1/get/statuses/mentions_timeline
I am sending the request to google maps api services to calculate the distance like this url:
$apiURL = "http://maps.google.com/maps/geo?&output=xml&key=AIzaSyCYz5Kpw4xTYVwAUibaMIUVBcaL-RfTumk&q=myAddress"
I am trying to get the response using file_get_contents($apiURL), & it is working well with my Local system. When i uploaded the same file to the server, the output of file_get_contents($apiURL) is appearing to be null & giving error like -
Warning:
file_get_contents(http://maps.google.com/maps/geo?&output=xml&key=AIzaSyCYz5Kpw4xTYVwAUibaMIUVBcaL-RfTumk&q=Aerekere
%2Cbangalore%2Ckarnataka) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /mnt/stor2-wc1-dfw1/410304/hfg.mpadusa.com/web/content/components/com_helping/controllers/distance.php
on line 108.
I have checked couple of things like
allow_url_fopen : On it's ok
New ApI key to the Linux server.
In local windows system, all response is ok.
What might me the issue. Any help is really appreciated.
file_get_contents is often disabled/blocked on web servers due to security risks when accessing external content (e.g. through http).
As a matter of good practice, always use curl functions to get external content, including calls to the google API. You can find plenty of examples of using curl on the web, but a simple place to start is the manual: http://au2.php.net/curl_exec
I am working on a script that fetches csv files from a web server. I am using file_get_contents presently. Sometimes i get the message
Warning: file_get_contents failed to open stream: Connection timed out
I assume it can be due to website being down. Or can there be a situation where the website is fine but still this warning shows up. Also what advantage does CURL provide over this function.
this is because the remote url is having 404 error.
For accessing remote files, you should use cURL. You can set cURL to timeout quietly if the remote server takes too long.