This repository has been archived by the owner on Oct 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
78 lines (67 loc) · 2.93 KB
/
search.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* retrieve more information about a certain package and overwrite the input parameters
* @param string $thePackageNameStr
* @param string $theAppCategoryStr
* @param string $thePermCSV
* @return array - updated [$thePackageNameStr, $theAppCategoryStr, $thePermCSV]
*/
function getPermsAndCategory($thePackageNameStr = '', $theAppCategoryStr = false, $thePermCSV = false) {
#php market api - includes must be in this order, especially middle two
include("MarketSession_config.php");
include("proto/protocolbuffers.inc.php");
include("proto/market.proto.php");
include("MarketSession.php");
# create session, and auth with google servers --> auth token
$session = new MarketSession();
$session->login(GOOGLE_EMAIL, GOOGLE_PASSWD);
$session->setAndroidId(ANDROID_DEVICEID);
#the search loop
$myEntriesFetchCount = 10;
$myPackageTotalCount = 0; //number of apps had to search through
$mySearchLoopCountLimit = 10;
$mySearchLoopCount = 0;
while (empty($thePermCSV) && empty($theAppCategoryStr)) {
#create market search request
$ar = new AppsRequest();
$ar->setQuery($thePackageNameStr);
$ar->setOrderType(AppsRequest_OrderType::NEWEST);
$ar->setStartIndex(($mySearchLoopCount * $myEntriesFetchCount));
$ar->setEntriesCount($myEntriesFetchCount);
$ar->setWithExtendedInfo(true);
$reqGroup = new Request_RequestGroup();
$reqGroup->setAppsRequest($ar);
#query the Android market servers using request and auth token
$response = $session->execute($reqGroup);
#get the response
$groups = $response->getResponsegroupArray();
#grab the first matching package
foreach ($groups as $rg) {
if (!empty($thePermCSV) && !empty($theAppCategoryStr))
break; //do not overwrite old values
$appsResponse = $rg->getAppsResponse();
$apps = $appsResponse->getAppArray();
foreach ($apps as $app) {
if (!empty($thePermCSV) && !empty($theAppCategoryStr))
break; //do not overwrite old values
$myPackageTotalCount++;
$aPackageName = $app->getPackageName();
if ($thePackageNameStr == $aPackageName) { //if there is a match ... grab first
if (empty($theAppCategoryStr)) {
$theAppCategoryStr = $app->getExtendedInfo()->getCategory();
}
if (empty($thePermCSV)) {
$aPermArray = $app->getExtendedInfo()->getPermissionIdArray();
$thePermCSV = implode(",", $aPermArray);
}
break;
}
}
}
$mySearchLoopCount++;
if ($mySearchLoopCount >= $mySearchLoopCountLimit)
break;
}
return (Array($thePackageNameStr, $theAppCategoryStr, $thePermCSV));
}
?>