I'm trying to do a composite search in bing search API using php. From this documentation i got this.
https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=%27web%2bnews%27&Query=%27XBox%27&$top=1 This gives some result which i don't know to parse and show the result. I tried `simplexml_load_file()` to parse but no use.
If i mention json format request like below i get a bad request sent error( failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request) and file_get_contents() error
https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=%27web%2bnews%27&?$format=json&Query=%27XBox%27&$top=1
How to get the result with json?
Correct query for you is: (I removed "?" before $format=json)
https://api.datamarket.azure.com/Data.ashx/Bing/Search/Composite?Sources=%27web%2bnews%27&$format=json&Query=%27XBox%27&$top=1
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.
I am using cURL to get and post some json array to api.natera.com
When I am curl Get to https://api.natera.com/ it returns 200 OK.
but to https://api.natera.com/2.0/jobs/sequencingRun it gives 404 Not Found.
When I am using OPTIONS to above link instead of GET, it returns 200.
Please help
That endpoint returns the following json response...
{"error":"Not Found"}
I don't know of a webserver that returns this response as a standard 404, so you are probably hitting the service you are trying to hit. Is there an API doc for this endpoint? You might need to include some query string args or something.
I have a website with a user input. After the user inputs something, an API (JSON) is queried based on the input.
Every now and then the API query fails and outputs the query URL.
file_get_contents(http://...id=...password=...&input=...): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /www/htdocs/....php
The query URL contains a password which is, of course, secret. How can I prevent the page to output the failed request?
Best
Benjamin
You should have error reporting off for a production server, but as a quick fix you can use the error suppression symbol #:
$resp = #file_get_contents(...);
Obviously you will still need to handle a failed call by checking the return value:
if($resp==false)//failed
I am attempting to utilize the USPS API to do some address verification/validation.
I'm sending this XML to http://testing.shippingapis.com/ShippingAPITest.dll:
<AddressValidateRequest%20USERID="xxxxx"><Address ID="0"><Address1></Address1><Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>
This is the same XML that is shown in their documentation for test requests. However, I always get an HTML (instead of XML) response that is a 501 Not Implmented error. Anyone familiar with this API know what might be going on? I'm using curl (in php) to make the request
UPDATE: When I make the request by typing the url into a browser with get params, it seems to work fine, but i get the error mentioned above using php/curl or just curl from the command line.
UPDATE: If I use file_get_contents with the url, I get a 400 bad request error - but if i urlencode, it works great - solution accepted.
Not familiar with the API, but:
Do you need the %20 after AddressValidateRequest? Does it work when that is replaced by a space?
Also, do you need to use CURL? Could you just use fopen() or file_get_contents() and then use the GET parameters which you mention work OK?