├── .gitignore
├── LICENCE
├── README.md
├── composer.json
├── examples
├── local.php.example
├── test_categories.php
├── test_screenshot.php
├── test_search.php
└── test_top.php
└── src
├── MarketSession.php
└── proto
├── market.proto
├── market.proto.php
├── protoc-gen-php
├── .gitignore
├── Makefile
├── README
├── addressbook.proto
├── php_options.proto
├── protoc-gen-php.cc
├── protocolbuffers.inc.php
├── strutil.cc
├── strutil.h
└── test.php
└── protocolbuffers.inc.php
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | .project
3 |
--------------------------------------------------------------------------------
/LICENCE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | PHP Implementation of JAVA Android API for pulling data from
294 | Android Marketplace
295 | Copyright (C) 2014 Onder Vincent Koc & Niklas Nilsson
296 |
297 | This program is free software; you can redistribute it and/or modify
298 | it under the terms of the GNU General Public License as published by
299 | the Free Software Foundation; either version 2 of the License, or
300 | (at your option) any later version.
301 |
302 | This program is distributed in the hope that it will be useful,
303 | but WITHOUT ANY WARRANTY; without even the implied warranty of
304 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
305 | GNU General Public License for more details.
306 |
307 | You should have received a copy of the GNU General Public License along
308 | with this program; if not, write to the Free Software Foundation, Inc.,
309 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
310 |
311 | Also add information on how to contact you by electronic and paper mail.
312 |
313 | If the program is interactive, make it output a short notice like this
314 | when it starts in an interactive mode:
315 |
316 | Gnomovision version 69, Copyright (C) year name of author
317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
318 | This is free software, and you are welcome to redistribute it
319 | under certain conditions; type `show c' for details.
320 |
321 | The hypothetical commands `show w' and `show c' should show the appropriate
322 | parts of the General Public License. Of course, the commands you use may
323 | be called something other than `show w' and `show c'; they could even be
324 | mouse-clicks or menu items--whatever suits your program.
325 |
326 | You should also get your employer (if you work as a programmer) or your
327 | school, if any, to sign a "copyright disclaimer" for the program, if
328 | necessary. Here is a sample; alter the names:
329 |
330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
331 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
332 |
333 | {signature of Ty Coon}, 1 April 1989
334 | Ty Coon, President of Vice
335 |
336 | This General Public License does not permit incorporating your program into
337 | proprietary programs. If your program is a subroutine library, you may
338 | consider it more useful to permit linking proprietary applications with the
339 | library. If this is what you want to do, use the GNU Lesser General
340 | Public License instead of this License.
341 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Android Marketplace API (PHP)
2 |
3 | [](https://doi.org/10.5281/zenodo.14769247)
4 |
5 | ## Overview
6 |
7 | This is a PHP implementation of the Java Android Market API. Used to connect to the Android Marketplace (Google Play Store) using PHP. This is an un-official API as an official API currently does not exist.
8 |
9 | ***
10 |
11 | #### Connection Settings & Connection Issues
12 | How to edit the local.php file for Google Account and Device ID, please read the following points below.
13 | ###### Google Account
14 | We have seen numerous blocks from Google this is where you get a return for a 403/400 error. The best way to deal with this is to sleep between requests. Where we have seen library working on localhost then on a server not connecting is due to Google showing captcha.
15 |
16 | ###### Captcha
17 | Please [enable two-factor authentication](https://www.google.com/landing/2step/) for your Google Account (or use an other Google Account) then create an application password. Use the application password in the local.php file for connecting to Google. If your still getting blocks please use the captcha overide by using the following url logged in on the same Google Account on your Desktop [Google Unlock Captcha](https://accounts.google.com/DisplayUnlockCaptcha)
18 |
19 | ###### Android Device ID
20 | The android device ID can easily be found using thrid-party applications like [Device ID - Google Play Store](https://play.google.com/store/apps/details?id=com.evozi.deviceid&hl=en)
21 |
22 | ***
23 |
24 | #### Examples Provided
25 | * Category Search
26 | * Pulling App Detailed Data (Screenshot)
27 | * Normal Search (Keyword)
28 | * Top Apps Search
29 |
30 | For examples please read the examples avalible on the [wiki](https://github.com/splitfeed/android-market-api-php/wiki)
31 |
32 | #### Issues & Bug's
33 | For Issues please use the [Github Issues Page](https://github.com/splitfeed/android-market-api-php/issues).
34 |
35 | Alternativley you can also talk to other developers on the [Google Groups Page](https://groups.google.com/forum/#!forum/android-market-api-php)
36 |
37 | ***
38 |
39 | ## Credits & Licence
40 |
41 | #### Credits
42 | [JAVA Android Marketplace API](https://code.google.com/p/android-market-api/)
43 |
44 | [Protoc Gen PHP](https://github.com/bramp/protoc-gen-php)
45 |
46 | #### Licence
47 | GNU GPL v2.0
48 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "splitfeed/android-market-api-php",
3 | "description": "PHP implementation of the Java Android Market API",
4 | "license": "GPL-2.0-or-later",
5 | "authors": [
6 | {
7 | "name": "Contributors",
8 | "homepage": "https://github.com/koconder/android-market-api-php/graphs/contributors"
9 | }
10 | ],
11 | "autoload": {
12 | "classmap": ["src"]
13 | }
14 | }
--------------------------------------------------------------------------------
/examples/local.php.example:
--------------------------------------------------------------------------------
1 | login(GOOGLE_EMAIL, GOOGLE_PASSWD);
11 | $session->setAndroidId(ANDROID_DEVICEID);
12 | sleep(1);#Reduce Throttling
13 | }catch(Exception $e){
14 | echo "Exception: ".$e->getMessage()."\n";
15 | echo "ERROR: cannot login as " . GOOGLE_EMAIL;
16 | exit(1);
17 | }
18 |
19 | $cr = new CategoriesRequest();
20 | $reqGroup = new Request_RequestGroup();
21 | $reqGroup->setCategoriesRequest($cr);
22 |
23 | //Fetch Request
24 | try{
25 | $response = $session->execute($reqGroup);
26 | }catch(Exception $e){
27 | echo "Exception: ".$e->getMessage();
28 | }
29 |
30 | $groups = $response->getResponsegroupArray();
31 | foreach ($groups as $rg) {
32 | $categoriesResponse = $rg->getCategoriesResponse();
33 | $categories = $categoriesResponse->getCategoriesArray();
34 | foreach ($categories as $category) {
35 | echo $category->getTitle()."
";
36 |
37 | $subcategories = $category->getSubCategoriesArray();
38 | foreach ($subcategories as $subcategory) {
39 | echo "- ".$subcategory->getTitle()."
";
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/examples/test_screenshot.php:
--------------------------------------------------------------------------------
1 | login(GOOGLE_EMAIL, GOOGLE_PASSWD);
11 | $session->setAndroidId(ANDROID_DEVICEID);
12 | sleep(1);#Reduce Throttling
13 | }catch(Exception $e){
14 | echo "Exception: ".$e->getMessage()."\n";
15 | echo "ERROR: cannot login as " . GOOGLE_EMAIL;
16 | exit(1);
17 | }
18 |
19 | //Build Request
20 | $appId = "7059973813889603239";
21 | $imageId = 1;
22 | $gir = new GetImageRequest();
23 | $gir->setImageUsage(GetImageRequest_AppImageUsage::SCREENSHOT);
24 | $gir->setAppId($appId);
25 | $gir->setImageId($imageId);
26 |
27 | $reqGroup = new Request_RequestGroup();
28 | $reqGroup->setImageRequest($gir);
29 |
30 | //Fetch Request
31 | try{
32 | $response = $session->execute($reqGroup);
33 | }catch(Exception $e){
34 | echo "Exception: ".$e->getMessage();
35 | }
36 |
37 | //Loop And Display
38 | $groups = $response->getResponsegroupArray();
39 | #echo "
".print_r($groups, true)."";
40 | foreach ($groups as $rg) {
41 | $imageResponse = $rg->getImageResponse();
42 | file_put_contents("../".$appId."_".$imageId.".png", $imageResponse->getImageData());
43 |
44 | ?>
">login(GOOGLE_EMAIL, GOOGLE_PASSWD);
11 | $session->setAndroidId(ANDROID_DEVICEID);
12 | sleep(1);#Reduce Throttling
13 | }catch(Exception $e){
14 | echo "Exception: ".$e->getMessage()."\n";
15 | echo "ERROR: cannot login as " . GOOGLE_EMAIL;
16 | exit(1);
17 | }
18 |
19 | //Build Request
20 | $ar = new AppsRequest();
21 | $ar->setQuery($_GET["search"] ? $_GET["search"] : "froyo");
22 | #$ar->setOrderType(AppsRequest_OrderType::NONE);
23 | $ar->setStartIndex(0);
24 | $ar->setEntriesCount(5);
25 |
26 | $ar->setWithExtendedInfo(true);
27 | #$ar->setViewType(AppsRequest_ViewType::PAID);
28 | #$ar->setAppType(AppType::WALLPAPER);
29 |
30 | $reqGroup = new Request_RequestGroup();
31 | $reqGroup->setAppsRequest($ar);
32 |
33 | //Fetch Request
34 | try{
35 | $response = $session->execute($reqGroup);
36 | }catch(Exception $e){
37 | echo "Exception: ".$e->getMessage();
38 | }
39 |
40 | //Loop And Display
41 | $groups = $response->getResponsegroupArray();
42 | foreach ($groups as $rg) {
43 | $appsResponse = $rg->getAppsResponse();
44 | $apps = $appsResponse->getAppArray();
45 | foreach ($apps as $app) {
46 | echo $app->getTitle()." (".$app->getId().")
";
47 | echo $app->getExtendedInfo()->getDescription()."
";
48 |
49 | //Get comments
50 | echo "";
51 | $cr = new CommentsRequest();
52 | $cr->setAppId($app->getId());
53 | $cr->setEntriesCount(3);
54 |
55 | $reqGroup = new Request_RequestGroup();
56 | $reqGroup->setCommentsRequest($cr);
57 |
58 | $response = $session->execute($reqGroup);
59 | $groups = $response->getResponsegroupArray();
60 | foreach ($groups as $rg) {
61 | $commentsResponse = $rg->getCommentsResponse();
62 |
63 | $comments = $commentsResponse->getCommentsArray();
64 | foreach ($comments as $comment) {
65 | echo "".$comment->getAuthorName()." [".str_repeat("*", $comment->getRating())."]
";
66 | echo $comment->getText()."
";
67 | }
68 | }
69 |
70 | echo "
";
71 | }
72 | }
--------------------------------------------------------------------------------
/examples/test_top.php:
--------------------------------------------------------------------------------
1 | login(GOOGLE_EMAIL, GOOGLE_PASSWD);
11 | $session->setAndroidId(ANDROID_DEVICEID);
12 | sleep(1);#Reduce Throttling
13 | }catch(Exception $e){
14 | echo "Exception: ".$e->getMessage()."\n";
15 | echo "ERROR: cannot login as " . GOOGLE_EMAIL;
16 | exit(1);
17 | }
18 |
19 | //Build Request
20 | $ar = new AppsRequest();
21 | $ar->setOrderType(AppsRequest_OrderType::POPULAR);
22 | $ar->setStartIndex(0);
23 | $ar->setEntriesCount(5);
24 | $ar->setViewType(AppsRequest_ViewType::PAID);
25 | $ar->setCategoryId("ARCADE");
26 | $reqGroup = new Request_RequestGroup();
27 | $reqGroup->setAppsRequest($ar);
28 |
29 | //Fetch Request
30 | try{
31 | $response = $session->execute($reqGroup);
32 | }catch(Exception $e){
33 | echo "Exception: ".$e->getMessage();
34 | }
35 |
36 | //Loop And Display
37 | $groups = $response->getResponsegroupArray();
38 | foreach ($groups as $rg) {
39 | $appsResponse = $rg->getAppsResponse();
40 | $apps = $appsResponse->getAppArray();
41 | foreach ($apps as $app) {
42 | echo $app->getTitle()." (".$app->getId().")
";
43 |
44 | //Get comments
45 | echo "";
46 | $cr = new CommentsRequest();
47 | $cr->setAppId($app->getId());
48 | $cr->setEntriesCount(3);
49 |
50 | $reqGroup = new Request_RequestGroup();
51 | $reqGroup->setCommentsRequest($cr);
52 |
53 | $response = $session->execute($reqGroup);
54 | $groups = $response->getResponsegroupArray();
55 | foreach ($groups as $rg) {
56 | $commentsResponse = $rg->getCommentsResponse();
57 |
58 | $comments = $commentsResponse->getCommentsArray();
59 | foreach ($comments as $comment) {
60 | echo "".$comment->getAuthorName()." [".str_repeat("*", $comment->getRating())."]
";
61 | echo $comment->getText()."
";
62 | }
63 | }
64 |
65 | echo "
";
66 | }
67 | }
--------------------------------------------------------------------------------
/src/MarketSession.php:
--------------------------------------------------------------------------------
1 |
10 | *
11 | *
12 | */
13 | class MarketSession {
14 | public $context = NULL;
15 | public $authSubToken = "";
16 |
17 | /**
18 | *
19 | */
20 | function __construct () {
21 | $this->context = new RequestContext();
22 | $this->context->setUnknown1(0);
23 | $this->context->setVersion(8013013);
24 | $this->context->setDeviceAndSdkVersion("crespo:8");
25 |
26 | $this->context->setUserLanguage("en");
27 | $this->context->setUserCountry("US");
28 |
29 | $this->setOperatorTmobile();
30 | }
31 |
32 | function setOperatorTmobile() {
33 | $this->setOperator("T-Mobile", "310260");
34 | }
35 |
36 | public function setOperatorSFR() {
37 | $this->setOperator("F SFR", "20810");
38 | }
39 |
40 | public function setOperatorO2() {
41 | $this->setOperator("o2 - de", "26207");
42 | }
43 |
44 | public function setOperatorSimyo() {
45 | $this->setOperator("E-Plus", "simyo", "26203", "26203");
46 | }
47 |
48 | public function setOperatorSunrise() {
49 | $this->setOperator("sunrise", "22802");
50 | }
51 |
52 | public function setOperator($alpha, $simAlpha, $numeric = "", $simNumeric = "") {
53 | if (!$numeric && !$simNumeric) {
54 | $this->context->setOperatorAlpha($alpha);
55 | $this->context->setSimOperatorAlpha($alpha);
56 |
57 | $this->context->setOperatorNumeric($simAlpha);
58 | $this->context->setSimOperatorNumeric($simAlpha);
59 |
60 | } else {
61 | $this->context->setOperatorAlpha($alpha);
62 | $this->context->setSimOperatorAlpha($simAlpha);
63 |
64 | $this->context->setOperatorNumeric($numeric);
65 | $this->context->setSimOperatorNumeric($simNumeric);
66 | }
67 | }
68 |
69 | /**
70 | *
71 | * @param unknown_type $email
72 | * @param unknown_type $password
73 | */
74 | public function login($email, $password) {
75 | $postFields = array(
76 | "Email" => $email,
77 | "Passwd" => $password,
78 | "service" => "android",
79 | "accountType" => "GOOGLE",
80 | );
81 | $post = "";
82 | foreach ($postFields as $field => $val) {
83 | $post .= $field."=".urlencode($val)."&";
84 | }
85 |
86 | // create a new cURL resource
87 | $ch = curl_init();
88 | curl_setopt($ch, CURLOPT_URL, "https://www.google.com/accounts/ClientLogin");
89 | curl_setopt($ch, CURLOPT_HEADER, 0);
90 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
91 | curl_setopt($ch, CURLOPT_POST, 1);
92 | curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
93 | @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
94 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
95 |
96 |
97 | $headers = array(
98 | //"User-Agent: Android-Market/2 (sapphire PLAT-RC33); gzip",
99 | //"Content-Type: application/x-www-form-urlencoded",
100 | //"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
101 |
102 | //New Headers - Old Ones Commented Out for Refernce
103 | "User-Agent: Android-Finsky/3.7.13 (api=3,versionCode=8013013,sdk=15,device=crespo,hardware=herring,product=soju)",
104 | "Content-Type: application/x-www-form-urlencoded",
105 | "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
106 | );
107 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
108 |
109 | $ret = curl_exec($ch);
110 | curl_close($ch);
111 |
112 | $aRet = explode("\n", $ret);
113 | foreach ($aRet as $line) {
114 | if (substr($line,0,5) == "Auth=") {
115 | $this->authSubToken = substr($line,5);
116 | $this->context->setAuthSubToken($this->authSubToken);
117 | return $this->authSubToken;
118 | }
119 | }
120 |
121 | return false;
122 | }
123 |
124 | /**
125 | *
126 | * @param integer $id Android Device ID
127 | */
128 | public function setAndroidId($deviceId) {
129 | $this->context->setAndroidId($deviceId);
130 | }
131 |
132 | /**
133 | * Validate all settings needed to make a request
134 | */
135 | public function validate() {
136 | return true;
137 |
138 | //Check login
139 | /*
140 | if (!$this->context->hasAuthSubToken) return false;
141 |
142 | //Check androidId
143 | if (!$this->context->hasAndroidId) return false;
144 |
145 | return true;
146 | */
147 | }
148 |
149 | /**
150 | *
151 | * @param unknown_type $requestGroup
152 | */
153 | public function execute($requestGroup) {
154 | $request = new Request();
155 | $request->setContext($this->context);
156 | $request->addRequestGroup($requestGroup);
157 |
158 | return $this->executeProtobuf($request);
159 | }
160 |
161 | /**
162 | *
163 | * @param Request $request
164 | * @return Response
165 | */
166 | public function executeProtobuf($request) {
167 | if (!$this->validate()) {
168 | throw new Exception("Missing authentication or Android ID");
169 | }
170 |
171 | $http = $this->executeRawHttpQuery($this->protobufToStr($request));
172 |
173 | $fp = fopen("php://memory", "w+b");
174 | fwrite($fp, $http, strlen($http));
175 | rewind($fp);
176 | $response = new Response();
177 | $response->read($fp);
178 |
179 | return $response;
180 | }
181 |
182 | private function protobufToStr($protoBuf) {
183 | $fp = fopen("php://memory", "w+b");
184 | $protoBuf->write($fp);
185 |
186 | rewind($fp);
187 | $str = '';
188 | while (!feof($fp)) {
189 | $str .= fread($fp, 8192);
190 | }
191 |
192 | return $str;
193 | }
194 |
195 | /**
196 | *
197 | * @param unknown_type $request
198 | */
199 | private function executeRawHttpQuery($request) {
200 | $ch = curl_init();
201 | curl_setopt($ch, CURLOPT_URL, "https://android.clients.google.com/market/api/ApiRequest");
202 | curl_setopt($ch, CURLOPT_HEADER, 0);
203 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
204 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
205 | curl_setopt($ch, CURLOPT_POST, 1);
206 | curl_setopt($ch, CURLOPT_COOKIE, "ANDROID=".$this->authSubToken);
207 | //curl_setopt($ch, CURLOPT_USERAGENT, "Android-Market/2 (sapphire PLAT-RC33); gzip");
208 | curl_setopt($ch, CURLOPT_USERAGENT, "Android-Finsky/3.7.13 (api=3,versionCode=8013013,sdk=15,device=crespo,hardware=herring,product=soju)");
209 |
210 | $post = "version=2&request=".base64_encode($request);
211 | curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
212 |
213 | $headers = array(
214 | "Content-Type: application/x-www-form-urlencoded",
215 | "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
216 | 'Content-Length: '.strlen($post)
217 | );
218 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
219 |
220 | $ret = curl_exec($ch);
221 |
222 | $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
223 | if ($http_code != 200) {
224 | throw new Exception("HTTP request returned code $http_code");
225 | }
226 |
227 | curl_close($ch);
228 |
229 | $ret = $this->gzdecode($ret);
230 | return $ret;
231 | }
232 |
233 | /**
234 | * Borrowed from http://php.net/manual/en/function.gzdecode.php until a better solution is found
235 | *
236 | * Written by katzlbtjunk at hotmail dot com
237 | */
238 | private function gzdecode($data,&$filename='',&$error='',$maxlength=null){
239 | $len = strlen($data);
240 | if ($len < 18 || strcmp(substr($data,0,2),"\x1f\x8b")) {
241 | $error = "Not in GZIP format.";
242 | return null; // Not GZIP format (See RFC 1952)
243 | }
244 | $method = ord(substr($data,2,1)); // Compression method
245 | $flags = ord(substr($data,3,1)); // Flags
246 | if ($flags & 31 != $flags) {
247 | $error = "Reserved bits not allowed.";
248 | return null;
249 | }
250 | // NOTE: $mtime may be negative (PHP integer limitations)
251 | $mtime = unpack("V", substr($data,4,4));
252 | $mtime = $mtime[1];
253 | $xfl = substr($data,8,1);
254 | $os = substr($data,8,1);
255 | $headerlen = 10;
256 | $extralen = 0;
257 | $extra = "";
258 | if ($flags & 4) {
259 | // 2-byte length prefixed EXTRA data in header
260 | if ($len - $headerlen - 2 < 8) {
261 | return false; // invalid
262 | }
263 | $extralen = unpack("v",substr($data,8,2));
264 | $extralen = $extralen[1];
265 | if ($len - $headerlen - 2 - $extralen < 8) {
266 | return false; // invalid
267 | }
268 | $extra = substr($data,10,$extralen);
269 | $headerlen += 2 + $extralen;
270 | }
271 | $filenamelen = 0;
272 | $filename = "";
273 | if ($flags & 8) {
274 | // C-style string
275 | if ($len - $headerlen - 1 < 8) {
276 | return false; // invalid
277 | }
278 | $filenamelen = strpos(substr($data,$headerlen),chr(0));
279 | if ($filenamelen === false || $len - $headerlen - $filenamelen - 1 < 8) {
280 | return false; // invalid
281 | }
282 | $filename = substr($data,$headerlen,$filenamelen);
283 | $headerlen += $filenamelen + 1;
284 | }
285 | $commentlen = 0;
286 | $comment = "";
287 | if ($flags & 16) {
288 | // C-style string COMMENT data in header
289 | if ($len - $headerlen - 1 < 8) {
290 | return false; // invalid
291 | }
292 | $commentlen = strpos(substr($data,$headerlen),chr(0));
293 | if ($commentlen === false || $len - $headerlen - $commentlen - 1 < 8) {
294 | return false; // Invalid header format
295 | }
296 | $comment = substr($data,$headerlen,$commentlen);
297 | $headerlen += $commentlen + 1;
298 | }
299 | $headercrc = "";
300 | if ($flags & 2) {
301 | // 2-bytes (lowest order) of CRC32 on header present
302 | if ($len - $headerlen - 2 < 8) {
303 | return false; // invalid
304 | }
305 | $calccrc = crc32(substr($data,0,$headerlen)) & 0xffff;
306 | $headercrc = unpack("v", substr($data,$headerlen,2));
307 | $headercrc = $headercrc[1];
308 | if ($headercrc != $calccrc) {
309 | $error = "Header checksum failed.";
310 | return false; // Bad header CRC
311 | }
312 | $headerlen += 2;
313 | }
314 | // GZIP FOOTER
315 | $datacrc = unpack("V",substr($data,-8,4));
316 | $datacrc = sprintf('%u',$datacrc[1] & 0xFFFFFFFF);
317 | $isize = unpack("V",substr($data,-4));
318 | $isize = $isize[1];
319 | // decompression:
320 | $bodylen = $len-$headerlen-8;
321 | if ($bodylen < 1) {
322 | // IMPLEMENTATION BUG!
323 | return null;
324 | }
325 | $body = substr($data,$headerlen,$bodylen);
326 | $data = "";
327 | if ($bodylen > 0) {
328 | switch ($method) {
329 | case 8:
330 | // Currently the only supported compression method:
331 | $data = gzinflate($body,$maxlength);
332 | break;
333 | default:
334 | $error = "Unknown compression method.";
335 | return false;
336 | }
337 | } // zero-byte body content is allowed
338 | // Verifiy CRC32
339 | $crc = sprintf("%u",crc32($data));
340 | $crcOK = $crc == $datacrc;
341 | $lenOK = $isize == strlen($data);
342 | if (!$lenOK || !$crcOK) {
343 | $error = ( $lenOK ? '' : 'Length check FAILED. ') . ( $crcOK ? '' : 'Checksum FAILED.');
344 | return false;
345 | }
346 | return $data;
347 | }
348 | }
349 | ?>
350 |
--------------------------------------------------------------------------------
/src/proto/market.proto:
--------------------------------------------------------------------------------
1 | option java_package = "com.gc.android.market.api.model";
2 |
3 | enum AppType {
4 | NONE = 0;
5 | APPLICATION = 1;
6 | RINGTONE = 2;
7 | WALLPAPER = 3;
8 | GAME = 4;
9 | }
10 |
11 | message AppsRequest {
12 | optional AppType appType = 1;
13 | optional string query = 2;
14 | optional string categoryId = 3;
15 | optional string appId = 4;
16 | optional bool withExtendedInfo = 6;
17 |
18 | enum OrderType {
19 | NONE = 0;
20 | POPULAR = 1;
21 | NEWEST = 2;
22 | FEATURED = 3;
23 | }
24 |
25 | enum ViewType {
26 | ALL = 0;
27 | FREE = 1;
28 | PAID = 2;
29 | }
30 |
31 | optional OrderType orderType = 7 [default = NONE];
32 | optional uint64 startIndex = 8;
33 | optional int32 entriesCount = 9;
34 | optional ViewType viewType = 10 [default = ALL];
35 | }
36 |
37 |
38 | message AppsResponse {
39 | repeated App app = 1;
40 | optional int32 entriesCount = 2;
41 | }
42 |
43 | message Category {
44 | optional int32 appType = 2;
45 | optional string title = 4;
46 | optional string categoryId = 3;
47 | optional string subtitle = 5;
48 | repeated Category subCategories = 8;
49 | }
50 |
51 | message CommentsRequest {
52 | optional string appId = 1;
53 | optional int32 startIndex = 2;
54 | optional int32 entriesCount = 3;
55 | }
56 |
57 | message CommentsResponse {
58 | repeated Comment comments = 1;
59 | optional int32 entriesCount = 2;
60 | }
61 |
62 | message App {
63 | optional string id = 1;
64 | optional string title = 2;
65 |
66 | optional AppType appType = 3 [default = NONE];
67 |
68 | optional string creator = 4;
69 | optional string version = 5;
70 | optional string price = 6;
71 | optional string rating = 7;
72 | optional int32 ratingsCount = 8;
73 |
74 | optional group ExtendedInfo = 12 {
75 | optional string description = 13;
76 | optional int32 downloadsCount = 14;
77 | repeated string permissionId = 15;
78 | optional int32 installSize = 16;
79 | optional string packageName = 17;
80 | optional string category = 18;
81 | optional string contactEmail = 20;
82 | optional string downloadsCountText = 23;
83 | optional string contactPhone = 26;
84 | optional string contactWebsite = 27;
85 |
86 | // V2
87 | optional int32 screenshotsCount = 30;
88 | optional string promoText = 31;
89 |
90 | // V3
91 | optional string recentChanges = 38;
92 | optional string promotionalVideo = 43;
93 | }
94 |
95 | optional string creatorId = 22;
96 | optional string packageName = 24;
97 | optional int32 versionCode = 25;
98 | //V2
99 | optional string priceCurrency = 32;
100 | optional int32 priceMicros = 33;
101 | }
102 |
103 | message Comment {
104 | optional string text = 1;
105 | optional int32 rating = 2;
106 | optional string authorName = 3;
107 | optional uint64 creationTime = 4;
108 | optional string authorId = 5;
109 | }
110 |
111 | message CategoriesRequest {
112 | }
113 |
114 | message CategoriesResponse {
115 | repeated Category categories = 1;
116 | }
117 |
118 | message SubCategoriesRequest {
119 | optional AppType appType = 1;
120 | }
121 |
122 | message SubCategoriesResponse {
123 | repeated Category category = 1;
124 | optional string subCategoryDisplay = 2;
125 | optional int32 subCategoryId = 3;
126 | }
127 |
128 | // operator : http://www.2030.tk/wiki/Android_market_switch
129 | // operatorNumeric : see http://en.wikipedia.org/wiki/Mobile_Network_Code
130 | message RequestContext {
131 | required string authSubToken = 1; // authsub token for service 'android'
132 | required int32 unknown1 = 2; // always 0
133 | required int32 version = 3; // always 1002
134 | required string androidId = 4; // android id converted to hexadecimal
135 | optional string deviceAndSdkVersion = 5; // ro.product.device ':' ro.build.version.sdk
136 | optional string userLanguage = 6; // ro.product.locale.language
137 | optional string userCountry = 7; // ro.product.locale.region
138 | optional string operatorAlpha = 8; // gsm.operator.alpha
139 | optional string simOperatorAlpha = 9; // gsm.sim.operator.alpha
140 | optional string operatorNumeric = 10; // gsm.operator.numeric
141 | optional string simOperatorNumeric = 11; // sim.gsm.operator.numeric
142 | }
143 |
144 | message GetImageRequest {
145 | optional string appId = 1;
146 | enum AppImageUsage {
147 | ICON = 0;
148 | SCREENSHOT = 1;
149 | SCREENSHOT_THUMBNAIL = 2;
150 | PROMO_BADGE = 3;
151 | BILING_ICON = 4;
152 | }
153 | optional AppImageUsage imageUsage = 3;
154 | optional string imageId = 4; // 0 or 1
155 | }
156 |
157 | message GetImageResponse {
158 | optional bytes imageData = 1;
159 | }
160 |
161 | message Request {
162 | optional RequestContext context = 1;
163 | repeated group RequestGroup = 2 {
164 | optional AppsRequest appsRequest = 4;
165 | optional CommentsRequest commentsRequest = 5;
166 | optional GetImageRequest imageRequest = 11;
167 | optional SubCategoriesRequest subCategoriesRequest = 14;
168 | optional CategoriesRequest categoriesRequest = 21;
169 | }
170 | }
171 |
172 | message ResponseContext {
173 | optional int32 result = 1;
174 | optional int32 unknown1 = 2;
175 | optional string unknown2 = 3;
176 | optional int32 unknown3 = 4;
177 | }
178 |
179 | message Response {
180 | repeated group ResponseGroup = 1 {
181 | optional ResponseContext context = 2;
182 | optional AppsResponse appsResponse = 3;
183 | optional CommentsResponse commentsResponse = 4;
184 | optional GetImageResponse imageResponse = 10;
185 | optional CategoriesResponse categoriesResponse = 20;
186 | optional SubCategoriesResponse subCategoriesResponse = 13;
187 | }
188 | }
--------------------------------------------------------------------------------
/src/proto/protoc-gen-php/.gitignore:
--------------------------------------------------------------------------------
1 | *.o
2 | *.pb.cc
3 | *.pb.h
4 | protoc-gen-php
5 |
--------------------------------------------------------------------------------
/src/proto/protoc-gen-php/Makefile:
--------------------------------------------------------------------------------
1 |
2 | CXX=g++
3 | #CXX=/home/bramp/llvm/Debug/bin/clang
4 |
5 | CXXFLAGS = -Wall -g
6 |
7 | INCLUDES =
8 | LFLAGS =
9 | LIBS = -lprotobuf -lprotoc -pthread
10 |
11 | SRCS = php_options.pb.cc strutil.cc protoc-gen-php.cc
12 | OBJS = $(SRCS:.cc=.o)
13 |
14 | MAIN = protoc-gen-php
15 |
16 | SHELL = /bin/sh
17 | .SUFFIXES:
18 | .SUFFIXES: .cc .o .proto
19 |
20 | .PHONY: all clean depend valgrind debug test Makefile
21 |
22 | all: $(MAIN)
23 | $(MAIN): $(OBJS)
24 | $(CXX) $(CXXFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LFLAGS) $(LIBS)
25 |
26 | php_options.pb.cc php_options.pb.h: php_options.proto
27 | protoc php_options.proto --cpp_out=. -I. -I/usr/include -I/usr/local/include
28 |
29 | .cc.o:
30 | $(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
31 |
32 | clean:
33 | $(RM) *.o $(MAIN) $(GENTESTS) php_options.pb.cc php_options.pb.h
34 |
35 | depend: $(SRCS)
36 | makedepend $(INCLUDES) $^
37 |
38 | valgrind: DEBUGCMD=gdb --args
39 | debug: all
40 | gdb --args protoc --php_out . --plugin=protoc-gen-php=./protoc-gen-php market.proto
41 |
42 | valgrind: DEBUGCMD=valgrind --trace-children=yes --leak-check=full
43 | valgrind: all test
44 |
45 | TESTS = test.proto addressbook.proto market.proto
46 | GENTESTS = $(TESTS:.proto=.proto.php)
47 | %.proto.php : %.proto $(MAIN)
48 | $(DEBUGCMD) protoc -I. -I/usr/include --php_out . --plugin=protoc-gen-php=./protoc-gen-php $<;
49 |
50 | test: $(GENTESTS)
51 | for file in $(TESTS); do \
52 | # echo | cat -n $${file}.php -; \
53 | php --syntax-check $${file}.php; \
54 | php test.php $${file}; \
55 | hd temp > temp.hd; \
56 | done ;
57 |
--------------------------------------------------------------------------------
/src/proto/protoc-gen-php/README:
--------------------------------------------------------------------------------
1 | This is a PHP Google Protocol Buffer Generator Plugin for protoc. It generates PHP code from a .proto file.
2 | by Andrew Brampton (c) 2010
3 |
4 | It's not finished, but supports most common features, and I'm currently using it in a production system.
5 |
6 | I've only tested the code on Debian Linux. To build just type "make". You may need the following libraries which can be installed from apt:
7 |
8 | libprotobuf-dev
9 | libprotobuf-lite6
10 | libprotobuf6
11 | libprotoc-dev
12 | libprotoc6
13 |
14 | Once compiled you can use it via protoc like so:
15 |
16 | protoc -I. -I/usr/include --php_out . --plugin=protoc-gen-php=./protoc-gen-php your.proto
17 |
18 | This should generate the file "your.proto.php", which should be able to encode and decode protocol buffer messages. When using the generated PHP code you must include the "protocolbuffers.inc.php" file.
19 |
20 | There are many TODOs to finish, for example writing better documentation :)
21 |
--------------------------------------------------------------------------------
/src/proto/protoc-gen-php/addressbook.proto:
--------------------------------------------------------------------------------
1 | // See README.txt for information and build instructions.
2 |
3 | package tutorial;
4 |
5 | option java_package = "com.example.tutorial";
6 | option java_outer_classname = "AddressBookProtos";
7 |
8 | option php_package = "com.example.tutorial";
9 | option php_outer_classname = "AddressBookProtos";
10 |
11 | message Person {
12 | required string name = 1;
13 | required int32 id = 2; // Unique ID number for this person.
14 | optional string email = 3;
15 |
16 | enum PhoneType {
17 | MOBILE = 0;
18 | HOME = 1;
19 | WORK = 2;
20 | }
21 |
22 | message PhoneNumber {
23 | required string number = 1;
24 | optional PhoneType type = 2 [default = HOME];
25 | }
26 |
27 | repeated PhoneNumber phone = 4;
28 | }
29 |
30 | // Our address book file is just one of these.
31 | message AddressBook {
32 | repeated Person person = 1;
33 | }
34 |
--------------------------------------------------------------------------------
/src/proto/protoc-gen-php/php_options.proto:
--------------------------------------------------------------------------------
1 | import "google/protobuf/descriptor.proto";
2 |
3 | message PHPFileOptions {
4 | optional string namespace = 1;
5 | optional bool skip_unknown = 2;
6 | }
7 |
8 | extend google.protobuf.FileOptions {
9 | optional PHPFileOptions php = 1004;
10 | }
11 |
--------------------------------------------------------------------------------
/src/proto/protoc-gen-php/protoc-gen-php.cc:
--------------------------------------------------------------------------------
1 | /**
2 | * PHP Protocol Buffer Generator Plugin for protoc
3 | * By Andrew Brampton (c) 2010
4 | *
5 | * TODO
6 | * Support the packed option
7 | * Lots of optimisations
8 | * Extensions
9 | * Services
10 | * Packages
11 | * Better validation (add code to check setted values are valid)
12 | * option optimize_for = CODE_SIZE/SPEED;
13 | */
14 | #include "strutil.h" // TODO This header is from the offical protobuf source, but it is not normally installed
15 |
16 | #include