-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGoogleReviews.php
64 lines (64 loc) · 2 KB
/
GoogleReviews.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
function getGoogleReviewScore($query) {
include "AlchInt.php";
include_once 'lib.php';
$result=json_decode(
file_get_contents(
"https://maps.googleapis.com/maps/api/place/textsearch/json?query="
.urlencode($query)
."&sensor=false&key=AIzaSyAqy2OnDc_LQU-JZfoBytrOmm10RnOpAlM"
),
true
);
if($result != null && array_key_exists("results", $result)) {
$result = $result["results"];
}
else {
return 2;
}
$sentiments = array();
foreach($result as $loc) {
if(array_key_exists("rating", $loc)) {
array_push($sentiments, $loc["rating"] / 5);
}
else {
array_push($sentiments, 0);
}
}
return count($sentiments) > 0 ? scoreCalc($sentiments) : 2;
/*
$IDs=array();
if(sizeof($result)<5)
for($x=0;$x<sizeof($result);$x++)
$IDs[$x]=$result[$x]["reference"];
else
for($x=0;$x<5;$x++)
$IDs[$x]=$result[$x]["reference"];
$sentiments = array();
for($x=0;$x<sizeof($IDs);$x++)
{
$reviews=json_decode(file_get_contents("https://maps.googleapis.com/maps/api/place/details/json?reference=".$IDs[$x]."&sensor=true&key=AIzaSyDs4lsfh1xT0F6xL_liNt6pPtvsp4rSd8g"),true)["result"];
if(isset($reviews["reviews"]))
$reviews=$reviews["reviews"];
else
continue;
for($y=0;$y<sizeof($reviews);$y++)
{
try
{
$outputAlch = $AlchemyObj->TextGetTextSentiment($reviews[$y]["text"], AlchemyAPI::JSON_OUTPUT_MODE);
$output = json_decode($outputAlch, true);
if(isset($output['docSentiment']['score']))
{
array_push($sentiments, $output['docSentiment']['score']);
}
}
catch(Exception $e){
//Weird errors...
}
}
}
return count($sentiments) > 0 ? scoreCalc($sentiments) : 2;
*/
}
?>