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.
Related
i am using yahoo finance API where i call an API and that gives me a CSV file. below are my codes.
$handle = fopen('http://download.finance.yahoo.com/d/quotes.csv?s=INFY&f=l1c1va2xj1b4j4dyekjm3m4rr5p5p6s7n=.csv', "r");
while execute this line it throws an warning that is
failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
i have spend more time on google but no result yet.
but sometimes its working fine without throwing any warning.
another things it also working fine in local. there is no working throw while execute
if anyone knows the exact solution please help me.
Thanks
Sanjib
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 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 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 trying to get postal codes from this site:
http://pl.wikisource.org/wiki/Lista_kod%C3%B3w_pocztowych_w_Polsce
My code is simple:
<?php
$postalCode = $_GET['code'];
$httpAddr = 'http://pl.wikisource.org/wiki/Lista_kod%C3%B3w_pocztowych_w_Polsce/Okr%C4%99g_'.$postalCode[0].'_'.$postalCode[0].$postalCode[1].'-xxx';
file_get_contents($httpAddr);
?>
But when i set $postalCode to 03-000 (also 01-000, 05-000, but for 07-000, 61-000, 62-000 is working) i am reciving error:
Warning: file_get_contents(http://pl.wikisource.org/wiki/Lista_kod%C3%B3w_pocztowych_w_Polsce/Okr%C4%99g_0_03-xxx): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /var/www/clients/client1/web4/web/ofix/test.php on line 5
Page address is correct, you can copy and past it in your web browser and it works.
Any ideas?
As Lightness Races in Orbit suspected, it does seem that the webserver is blocking PHP's request.
Using cURL instead of file_get_contents() reveals the details:
HTTP/1.0 403 Forbidden
Scripts should use an informative User-Agent string with contact information, or they may be IP-blocked without notice.
A web browser sends a valid User-Agent header in its request, which is why the page loads OK in your browser but not in PHP.
In my tests loading this URL in PHP, sometimes it succeeds with an HTTP status code of 200, other times it fails with 403. Notice that the error message says scripts may be blocked (ie. sometimes they may not be blocked).
Edit
See this question for more info: How to get results from the Wikipedia API with PHP?