I've been using the following code to scrape keywords from Google:
$data=file_get_contents('http://clients1.google.com/complete/search?hl=en&gl=us&q='.$keyword);
However, my script has suggest started showing these errors:
Warning: file_get_contents(http://clients1.google.com/complete/search?hl=en&gl=us&q=money) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /home/username/public_html/keywords.php on line 10
I'm guessing this is being caused by Google changing the link? Does anyone know what the new link would be or what I need to change in my code?
Try this:
$url = 'http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl=en-US&q=';
$data=file_get_contents($url . urlencode( $keyword ) );
Hope it helps.
Related
I am trying to fetch some data like first name, last name from LinkedIn. I am using the below code for the same. But I am getting NULL in response. I tried some solutions from SO and other websites but none of them worked.
Below is the code I am using:-
$url = 'http://api.linkedin.com/v1/people/~:(id,first-name,last-name,picture-urls::(original),headline,public-profile-url,location,industry,positions,email-address)?format=json&outh2_access_token='.$accessToken;
$user = file_get_contents($url,false);
var_dump(json_decode($user));
die();
Below is the response that I am getting.
[16-Jul-2018 12:27:20 Europe/London] PHP Warning: file_get_contents(http://api.linkedin.com/v1/people/~:(id,first-name,last-name,picture-urls::(original),headline,public-profile-url,location,industry,positions,email-address)?format=json&outh2_access_token=###########): failed to open stream: HTTP request failed! HTTP/1.0 401 Unauthorized
Basically what I want is to fetch the data from LinkedIn using php, if anybody has done this before please share the solution with me.
I'm trying to develop and Instagram application but I'm struggling to get a json inserting the access token via variable.
That's my code:
$personal = json_decode(file_get_contents('https://api.instagram.com/v1/users/self/?access_token={$accesstoken}'));
And the error that I receive is this:
PHP Warning: file_get_contents(https://api.instagram.com/v1/users/self/?access_token={$accesstoken}): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
I already tried to see if I get the variable $accesstoken from the previous form and it's all right, because if I echo-it on the page it pops up.
I tried the function preg_replace to understand if the problem were the white spaces, but nothing.
I don't want to use cURL if it is not mandatory.
What's wrong with the code (and me)?
Thanks in advance!
Edit:
As I answered to #FirstOne: yes, I already tried to put the variable (access token) manually and in this way it works.
Warning: simplexml_load_file(http://gdata.youtube.com/feeds/api/videos/b3a5BgqObEY): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
is the error that I get with the youtube feed in my site. I was told it was because a YouTube video was removed, but I don't know enough about PHP to fix this error. Can someone help push me in the right direction? When I searched for this error, all that came up was xml stuff and this is all in php so that doesn't help.
$feedURL = 'http://gdata.youtube.com/feeds/api/videos/'. $youtube->yt_videoId;
// read feed into SimpleXML object
$entry = simplexml_load_file($feedURL);
// parse video entry
$video = $main->parseVideoEntry($entry);
I'll keep looking, but thanks in advance if you have a good link for me to look at while I research this problem.
If you visit the url http://gdata.youtube.com/feeds/api/videos/b3a5BgqObEY you'll see "Private video", which is the reason you can't get the feed...
EDIT: You can use the V3 of the API to send an authentificated request; check this url to learn how to do it: https://developers.google.com/youtube/v3/
Greetings
I'm using the following line with to get the page content:
$handle = file_get_contents(
"http://www.mywebsite.com/index.php?show=users&action=msg§ion=send",
NULL,
NULL,
1000,
19000);
And then, I'm getting the following message:
Warning:
file_get_contents(http://www.mywebsite.com/index.php?show=users&action=msg §ion=send):
failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
(Please take a note at the bolded part).
What happened to it? Why does it changes the url param?
I don't think PHP is changing querystring parameters.
If you are reading that message in the browser, it should be just a matter of how the output is HTML formatted. So, the 403 error you are getting it should not be related to some unwanted url transformation.
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.