Does anybody have a PHP example of using the VirusTotal.com public API for URL scanning?
The API is available here:
http://www.virustotal.com/advanced.html
There's a Python/JSON example, but I'm not experienced with either :(
All you need is to retreive the report json using file_get_contents this way :
$json = file_get_contents('https://www.virustotal.com/api/get_url_report.json');
Then use json_decode to convert your json into a php array:
$array = json_decode($json);
to see results :
var_dump($array);
to post data use curl, related question.
A PHP example is available on that page (maybe it's new).
Related
I am making a website to display the data at https://api.captcoin.com/address/top/100. I need to be able to make the website take variables("address", "percent", "balance", and "rank") from this script and make them local variables in my site so I can display them. How can I take these variables and use them in my site?
First you need to get the remote page contents:
$remote = file_get_contents('link');
Then, since the data is in json format, you need to decode it using json_decode function.
$data = json_decode($remote, true);
true means that $remote should be decoded as associative array.
And finally you can access the data like an ordinary php array:
echo $data['top'][0]['address'];
Also, you should add some logic to handle situations when remote server is not accessible.
Use json_decode to convert the content of that url into an array and then search through it like you would through any array.
To get the actual content of the site please refer to this post Get file content from a URL?
You can either do it with javascript or php.
With javascript use this:
http://api.jquery.com/jquery.getjson/
You take the pages output and push them as variables to the php.
With php you can use
http://php.net/manual/en/function.json-decode.php
You make an array to push the json data into:
$object = array();
$json = file_get_contents('https://api.captcoin.com/address/top/100');
$object = json_decode ( string $json , true)
Be aware this is untested and read the json_decode api to customize the function-call.
spent a few hours trying to figure this out, but cannot for the life of me figure out what's going wrong.
All I'm trying to do is load this:
https://recruit.zoho.com/ats/EmbedResult.hr?jodigest=2cV.Sr2As6VxhLMxQGuTNij*g.Fb3J7ysduDs.AC9sU-&atslocale=en_GB&rawdata=json
which I believe is json, into either javascript/jquery or php and use the data.
I've looked into jsonp, followed some tutorials, used some demos as templates and just can't get the above data to work.
If anyone can shed some light it would be much appreciated. It really shouldn't be this complicated, but I don't know what's going wrong.
Yep, that's JSON. The site may not support JSONP, so you're gonna have to use PHP to do this.
This is untested, but should work.
<?php
$url = 'https://recruit.zoho.com/ats/EmbedResult.hr?jodigest=2cV.Sr2As6VxhLMxQGuTNij*g.Fb3J7ysduDs.AC9sU-&atslocale=en_GB&rawdata=json';
$JSON = file_get_contents($url);
// echo the JSON (you can echo this to JavaScript to use it there)
echo $JSON;
// You can decode it to process it in PHP
$data = json_decode($JSON);
var_dump($data);
?>
JSONP relies on the server to return a JSONP formatted response. Basically, to use JSONP the server needs to return a JSON string wrapped in a function invocation ({"foo":1} becomes func({"foo":1})).
As the server your using doesn't return a JSONP response, you cannot use JSONP, you can only use JSON.
This is a shame, as JSON cannot be used x-domain due to the same origin policy (SOP). Therefore, the only option you have is to use a proxy server, which retrieves the JSON from the server, and either gives it to you in JSONP (see Yahoo Pipes), or which is on the same domain as the requested page (write a simple PHP script to get the file using file_get_contents() and then echo the output), in which case it can return the JSON.
I breifly looked at the requirements and it looks like you need an API key as well as an account. I saw that the site provides services for XML and JSON only. It looks to be fairly well documented.
When you GET or POST this:
"http://translate.google.com/translate_a/t","client=t&sl=auto&tl=".urlencode($lang)."&text=".urlencode($text)
the response looks like this:
[[["автомобил","car","avtomobil",""]],,"en",,[["автомобил",[5],1,0,1000,0,1,0]],[["car",5,[["автомобил",1000,1,0],["автомобилот",0,1,0],["автомобили",0,1,0],["кола",0,1,0],["возило",0,1,0]],[[0,3]],"car"]],,,[["en","fr"]],30]
How to decode that? (maybe in json_decode style)
To get the api to return JSON change the parameter
client=t
to
client=p
//this will translate from en to ar -- you can change it for your needs
function translate_word($en){
$file_content = file_get_contents('http://translate.google.com/translate_a/t?client=p&sl=auto&tl=ar&hl=en&sc=2&ie=UTF-8&oe=UTF-8&uptl=ar&oc=1&prev=conf&psl=auto&ptl=en&otf=1&it=sel.8936&ssel=0&tsel=3&q='.str_replace(" ","%20",$en));
$obj = json_decode($file_content);
if(!empty($obj->sentences[0]->trans)){
return $obj->sentences[0]->trans;
}else{
return $en;
}
}
//how to use
echo translate_word("test translation process");
//if you do not know short codes for your language you can just open
translate.google.com and do described on screenshot
//you should have firebug extension installed on your browser
//if the answer was usefull please do not forget to vote up! thanks.
Try using PHP's json_decode function to convert that data to native PHP data types.
I am working with the JSON in which I have to fetch the location of particular city e.g: http://maps.google.com/maps/geo?q=Vanguard,CA,%20United%20States&output=json
Now in PHP how can I write the code to fetch the "Point" data ?
So long as you have allow_url_fopen on in php.ini, you can use file_get_contents(). You can then parse with json_decode().
$json = json_decode(file_get_contents('http://maps.google.com/maps/geo?q=Vanguard,CA,%20United%20States&output=json'), TRUE);
$json is now an array of your JSON data.
$json_data=file_get_contents($url);
allow_url_fopen should be on in this case.
Curl can be used as an alternate option
I advice using the cURL lib for this. (cUrL). It just offers more options and error handling then using alternatives like file_get_contents etc.
This question already has answers here:
Get information from JSON
(2 answers)
Closed 11 months ago.
I have been trying to use some API's from various services, At the moment im trying to retrieve data about a video on vimeo,
I have successfully got the file and read the contents, however, i do not know how to access each part of the file that is returned as a .json.
Basically, how do i access the data in the json file using PHP
Thanks
$file_contents = file_get_contents("http://vimeo.com/api/v2/group/awesome/videos.json"), true);
Read it into a variable using:
$data = json_decode($file_contents);
then you can access the parts using:
echo $data->id;
echo $data->title;
etc.
Just use print_r($data); to see all available fields.
Did you try the json_decode function?
If the file is just JSON, you can use json_decode:
$data = json_decode(file_get_contents("url here"), true);
and then access the data like a normal array. Of course you have to know the structure of the data you get in order to access it correctly. You can always use loops to iterate over it as well.
If the data is delivered as JSONP, you have to process it before, to remove the padding. I created a function for that.
Update:
In one of the comments you posted a link to the JSON file:
$data->video
does not work because
$data is an array. $data[0]->something will work
video does not exist as property of the object.
Do a print_r($data) to see the structure.