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
Related
getting a error on file_get_content it is replacing & to & hence i am getting d error. data which i am getting is in json format.
original url is: xyz.abc.com/index.php/DeviceDetails/GetDeviceHistory?tracking_id=70&start_time=2017-03-05 13:14:50&end_time=2017-03-08 13:14:50
<b>Warning</b>: file_get_contents(http://xyz.abc.com/index.php/DeviceDetails/GetDeviceHistory?tracking_id=70&start_time=2017-03-05 13:14:50&end_time=2017-03-08 13:14:50): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
in
<b>/home/abc/public_html/php/service.php</b> on line
<b>1855</b>
<br />
{"Status":"false","message":"No data found"}
please help me with this error
Make sure you actual URL is starting with http:// or https:// and use quotes while calling file_get_contents
file_get_contents("http://your_URL_here")
Try running PHP html_entity_decode() on your URL before you pass it to file_get_contents(): http://php.net/manual/en/function.html-entity-decode.php (as Kuldeep Singh says above, be sure you are passing the URL as a string :D)
I have had many many many problems similar to this. It could be a number of things, a missing header, invalid user agent, bad php.ini config, etc.
I would highly recommend using a cURL Library that allows you to customize headers, port, etc. of the request so you can properly debug. This is the custom PHP cURL library I use: https://gist.github.com/schwindy/e5798405d0b6269945bdf037a58f6a4d
Hope some of that helps. Good luck.
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.
I'm trying to create a simple script to fetch user profile data from an id.
For example
$link = json_decode(file_get_contents('http://graph.facebook.com/zuck'));
echo $link_>name;
The problem is that it's seems like facebook is limiting these kind of requests. Sometimes it's working, but sometimes I'm getting the following error :
Warning: file_get_contents(http://graph.facebook.com/zuck)
[function.file-get-contents]: failed to open stream: HTTP request
failed! HTTP/1.0 403 Forbidden
Try to use curl instead of file_get_contents and use curl_error to see why it returns 403. There's a request limit that you might reach and that might be the cause why it gives you 403.
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.
I've got a php file on my server that looks like this:
echo file_get_contents('http://server.com/some.file');
and I get the following error:
Warning: file_get_contents(http://server.com/some.file) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /path/to/php/file on line 6
What's got me confused is that if I link to the/full/server/path instead of http:// it seems to load fine. Also, I can get it to load content from other domains using http://, just not my own.
Any ideas?
As deceze sayd test the path in a browser. It should work the same as in PHP. If the path you write is correct check your URL rewrites (maybe you have them different for the server IP).