I have a bug in my code.
My code is:
<?php $opts = array(
'http'=>array(
'method'=>"GET",
'max_redirects' => 100
));
$context = stream_context_create($opts);
$url = 'https://fr.socialclub.rockstargames.com/member/m1ssashleex/games/gtav/snapmatic/ajax/search?Filter=MostRecent&page=1';
$file = file_get_contents($url, false, $context);
$vresponse = json_decode($file);
?>
<?php var_dump($vresponse); ?>
I testing all solutions, but i don't have success
error:
Message: file_get_contents(https://fr.socialclub.rockstargames.com/member/m1ssashleex/games/gtav/snapmatic/ajax/search?Filter=MostRecent&page=1): failed to open stream: HTTP request failed! HTTP/1.1 429
1) The error message says HTTP request failed! HTTP/1.1 429. 429 is the error code for too many requests. The server does not deliver the content cause you have exceeded the rate limit.
2) The page you want to get does not work if you are not logged in on that site.
Related
I call an API url with file_get_contents like this
$options_access_token = array(
'http'=>array(
'ignore_errors' => true,
'method'=>"POST",
'header'=>"Authorization:Bearer mykey"
)
);
$context = stream_context_create($options_access_token);
$access_token = file_get_contents($url_access_token, false, $context);
print_r($access_token);exit;
it give a "HTTP request failed! HTTP/1.0 400 Bad Request"
then i try ignore_errors' => true, on http request and it gave another error, it was "Client sent an HTTP request to an HTTPS server." the url is "http" protocol.
Any ideas what i do wrong or lacking? thanks for any answer it will be helpful
I already tried the following but it doesn't seem to work:
file_get_contents('http://username:password#example.com/requested.file');
And
$auth = base64_encode("username:password");
$context = stream_context_create(['http' => ['header' => "Authorization: Basic $auth"]]);
$homepage = file_get_contents("http://example.com/requested.file", false, $context );
I still keep getting a failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized.
I checked multiple times that the userdata I try to log in with is correct.
I have this php code and I'm trying to get content of image.jpg from url but I need to athuraize my self to the server and I did use the fowling code:
$user = 'username';
$pass = 'password';
$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode("$user:$pass")
)
));
$data = file_get_contents("http://mysite/User%20Photos/Profile%20Pictures/bmir_LThumb.jpg", false, $context);
My problem still getting this error:
failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized
I saw many situations like me and I tried their solution like this one but still having problem .
Any help ?
If using file_get_contents() to connect to Facebook,
$response = file_get_contents("https://graph.facebook.com/...?access_token=***");
echo "Response: ($response)\n";
And the server returns a non-OK HTTP status, PHP gives a generic error response, and suppresses the response. The body returned is empty.
file_get_contents(...): failed to open stream: HTTP/1.0 400 Bad Request
Response: ()
But if we use cURL, we see that Facebook actually returns a useful response body:
{"error":{"message":"An active access...","type":"OAuthException","code":2500}}
How can I make file_get_contents() return the response body regardless of HTTP errors?
You have to use stream_context_create():
$ctx = stream_context_create(array(
'http' => array (
'ignore_errors' => TRUE
)
));
file_get_contents($url, FALSE, $ctx);
You could ignore the errors file_get_contents throws
$opts = array(
'http'=>array(
'ignore_errors'=> true,
)
);
$context = stream_context_create($opts);
$file = file_get_contents('https://graph.facebook.com/...?access_token=***', false, $context);
var_dump($file);
It seems out of no where my server is acting up. and I'm getting this error.
failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
This is my code that I've had implemented for over a year now, and is confirmed working on a separate staging server.
$url = 'http://graph.facebook.com/10150624051911279/photos/all';
$response = json_decode(file_get_contents($url, true));
foreach ($response->data as $photo) {
echo '<li><a href="' . $photo->link . '" ><img class="img" src="timthumb.php?src=' . $photo->source . '&h=175&w=175" /></a></li>';
}
What could possibly be failing on my server to cause this issue. I'm stumped.
The request should fail, because to access that URL you need to obtain an access token. So Facebook returns
{
"error": {
"message": "An access token is required to request this resource.",
"type": "OAuthException",
"code": 104
}
}
with along with a "400 Bad Request" status. Additionally since you're opening an URL the second parameter of file_get_contents should be false (there is no point to search the include path, if you know it's not there).
To still get the response from Facebook and ignore the error you can do:
$url = 'http://graph.facebook.com/10150624051911279/photos/all';
$context = stream_context_create(array(
'http' => array(
'ignore_errors'=>true,
'method'=>'GET'
// for more options check http://www.php.net/manual/en/context.http.php
)
));
$response = json_decode(file_get_contents($url, false, $context));