api.txt 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. __ __ __
  2. / // / ____ ____ / /_
  3. / // /_/ __ `/ _ \/ __/
  4. /__ __/ /_/ / __/ /_
  5. /_/ \__, /\___/\__/
  6. /____/
  7. + Welcome to the 4get API documentation +
  8. + Terms of use
  9. Do NOT misuse the API. Misuses can include... ::
  10. 1. Serp SEO scanning
  11. 2. Intensive scraping
  12. 3. Any other activity that isn't triggered by a human
  13. 4. Illegal activities in Canada
  14. 5. Constant "test" queries while developping your program
  15. (please cache the API responses!)
  16. Examples of good uses of the API ::
  17. 1. A chatroom bot that presents users with search results
  18. 2. Personal use
  19. 3. Any other activity that is initiated by a human
  20. If you wish to engage in the activities listed under "misuses", feel
  21. free to download the source code of the project and running 4get
  22. under your own terms. Please respect the terms of use listed here so
  23. that this website may be available to all in the far future.
  24. Get your instance running here ::
  25. https://git.lolcat.ca/lolcat/4get
  26. Thanks!
  27. + Decode the data
  28. All payloads returned by the API are encoded in the JSON format. If
  29. you don't know how to tackle the problem, maybe programming is not
  30. for you.
  31. All of the endpoints use the GET method.
  32. + Check if an API call was successful
  33. All API responses come with an array index named "status". If the
  34. status is something else than the string "ok", something went wrong.
  35. The HTTP code will always be 200 as to not cause issues with CORS.
  36. + Get the next page of results
  37. All API responses come with an array index named "nextpage". To get
  38. the next page of results, you must make another API call with &npt.
  39. Example ::
  40. + First API call
  41. /api/v1/web?s=higurashi
  42. + Second API call
  43. /api/v1/web?npt=ddg1._rJ2hWmYSjpI2hsXWmYajJx < ... >
  44. You shouldn't specify the search term, only the &npt parameter
  45. suffices.
  46. The first part of the token before the dot (ddg1) refers to an
  47. array position on the serber's memory. The second part is an
  48. encryption key used to decode the data at that position. This way,
  49. it is impossible to supply invalid pagination data and it is
  50. impossible for a 4get operator to peek at the private data of the
  51. user after a request has been made.
  52. The tokens will expire as soon as they are used or after a 7 minutes
  53. inactivity period, whichever comes first.
  54. + Beware of null values!
  55. Most fields in the API responses can return "null". You don't need
  56. to worry about unset values.
  57. + API Parameters
  58. To construct a valid request, you can use the 4get web interface
  59. to craft a valid request, and replace "/web" with "/api/v1/web".
  60. + "date" and "time" parameters
  61. "date" always refer to a calendar date.
  62. "time" always refer to the duration of some media.
  63. They are both integers that uses seconds as its unit. The "date"
  64. parameter specifies the number of seconds that passed since January
  65. 1st 1970.
  66. ______ __ _ __
  67. / ____/___ ____/ /___ ____ (_)___ / /______
  68. / __/ / __ \/ __ / __ \/ __ \/ / __ \/ __/ ___/
  69. / /___/ / / / /_/ / /_/ / /_/ / / / / / /_(__ )
  70. /_____/_/ /_/\__,_/ .___/\____/_/_/ /_/\__/____/
  71. /_/
  72. + /api/v1/web
  73. + &extendedsearch
  74. When using the ddg(DuckDuckGo) scraper, you may make use of the
  75. &extendedsearch parameter. If you need rich answer data from
  76. additional sources like StackOverflow, music lyrics sites, etc.,
  77. you need to specify the value of (string)"true".
  78. The default value is "false" for API calls.
  79. + Parse the "spelling"
  80. The array index named "spelling" contains 3 indexes ::
  81. spelling:
  82. type: "including"
  83. using: "4chan"
  84. correction: '"4cha"'
  85. The "type" may be any of these 3 values. When rendering the
  86. autocorrect text inside your application, it should look like
  87. what follows right after the parameter value ::
  88. no_correction <Empty>
  89. including Including results for %using%. Did you mean
  90. %correction%?
  91. not_many Not many results for %using%. Did you mean
  92. %correction%?
  93. As of right now, the "spelling" is only available on
  94. "/api/v1/web".
  95. + Parse the "answer"
  96. The array index named "answer" may contain a list of multiple
  97. answers. The array index "description" contains a linear list of
  98. nodes that can help you construct rich formatted data inside of
  99. your application. The structure is similar to the one below:
  100. answer:
  101. 0:
  102. title: "Higurashi"
  103. description:
  104. 0:
  105. type: "text"
  106. value: "Higurashi is a great show!"
  107. 1:
  108. type: "quote"
  109. value: "Source: my ass"
  110. Each "description" node contains an array index named "type".
  111. Here is a list of them:
  112. text
  113. + title
  114. italic
  115. + quote
  116. + code
  117. inline_code
  118. link
  119. + image
  120. + audio
  121. Each individual node prepended with a "+" should be prepended by
  122. a newline when constructing the rendered description object.
  123. There are some nodes that differ from the type-value format.
  124. Please parse them accordingly ::
  125. + link
  126. type: "link"
  127. url: "https://lolcat.ca"
  128. value: "Visit my website!"
  129. + image
  130. type: "image"
  131. url: "https://lolcat.ca/static/pixels.png"
  132. + audio
  133. type: "audio"
  134. url: "https://lolcat.ca/static/whatever.mp3"
  135. The array index named "table" is an associative array. You can
  136. loop over the data using this PHP code, for example ::
  137. foreach($table as $website_name => $url){ // ...
  138. The rest of the JSON is pretty self explanatory.
  139. + /api/v1/images
  140. All images are contained within "image". The structure looks like
  141. below ::
  142. image:
  143. 0:
  144. title: "My awesome Higurashi image"
  145. source:
  146. 0:
  147. url: "https://lolcat.ca/static/profile_pix.png"
  148. width: 400
  149. height: 400
  150. 1:
  151. url: "https://lolcat.ca/static/pixels.png"
  152. width: 640
  153. height: 640
  154. 2:
  155. url: "https://tse1.mm.bing.net/th?id=OIP.VBM3BQg
  156. euf0-xScO1bl1UgHaGG"
  157. width: 194
  158. height: 160
  159. The last image of the "source" array is always the thumbnail, and is
  160. a good fallback to use when other sources fail to load. There can be
  161. more than 1 source; this is especially true when using the Yandex
  162. scraper, but beware of captcha rate limits.
  163. + /api/v1/videos
  164. The "time" parameter for videos may be set to "_LIVE". For live
  165. streams, the amount of people currently watching is passed in
  166. "views".
  167. + /api/v1/news
  168. Just make a request to "/api/v1/news?s=elon+musk". The payload
  169. has nothing special about it and is very self explanatory, just like
  170. the endpoint above.
  171. + /favicon
  172. Get the favicon for a website. The only parameter is "s", and must
  173. include the protocol.
  174. Example ::
  175. /favicon?s=https://lolcat.ca
  176. If we had to revert to using Google's favicon cache, it will throw
  177. an error in the X-Error header field. If Google's favicon cache
  178. also failed to return an image, or if you're too retarded to specify
  179. a valid domain name, a default placeholder image will be returned
  180. alongside the "404" HTTP error code.
  181. + /proxy
  182. Get a proxied image. Useful if you don't want to leak your user's IP
  183. address. The parameters are "i" for the image link and "s" for the
  184. size.
  185. Acceptable "s" parameters:
  186. portrait 90x160
  187. landscape 160x90
  188. square 90x90
  189. thumb 236x180
  190. cover 207x270
  191. original <Original resolution>
  192. You can also ommit the "s" parameter if you wish to view the
  193. original image. When an error occurs, an "X-Error" header field
  194. is set.
  195. + /audio
  196. Get a proxied audio file. Does not support "Range" headers, as it's
  197. only used to proxy small files.
  198. The parameter is "s" for the audio link.
  199. + Appendix
  200. If you have any questions or need clarifications, please send an
  201. email my way to will at lolcat.ca