Returns a list of results from Facebook public status updates for the given query. - query: string, or Result.id for NEWS and COMMENTS, - type : SEARCH, - start: 1, - count: maximum 100 for SEARCH and NEWS, 1000 for COMMENTS and LIKES. The
(self, query, type=SEARCH, start=1, count=10, cached=False, **kwargs)
| 2281 | }).download().split("=")[1] |
| 2282 | |
| 2283 | def search(self, query, type=SEARCH, start=1, count=10, cached=False, **kwargs): |
| 2284 | """ Returns a list of results from Facebook public status updates for the given query. |
| 2285 | - query: string, or Result.id for NEWS and COMMENTS, |
| 2286 | - type : SEARCH, |
| 2287 | - start: 1, |
| 2288 | - count: maximum 100 for SEARCH and NEWS, 1000 for COMMENTS and LIKES. |
| 2289 | There is an hourly limit of +-600 queries (actual amount undisclosed). |
| 2290 | """ |
| 2291 | # Facebook.search(type=SEARCH) returns public posts + author. |
| 2292 | # Facebook.search(type=NEWS) returns posts for the given author (id | alias | "me"). |
| 2293 | # Facebook.search(type=COMMENTS) returns comments for the given post id. |
| 2294 | # Facebook.search(type=LIKES) returns authors for the given author, post or comments. |
| 2295 | # An author is a Facebook user or other entity (e.g., a product page). |
| 2296 | if type not in (SEARCH, NEWS, COMMENTS, LIKES, FRIENDS): |
| 2297 | raise SearchEngineTypeError |
| 2298 | if type in (SEARCH, NEWS): |
| 2299 | max = 100 |
| 2300 | if type in (COMMENTS, LIKES): |
| 2301 | max = 1000 |
| 2302 | if type in (FRIENDS,): |
| 2303 | max = 10000 |
| 2304 | if not query or start < 1 or count < 1: |
| 2305 | return Results(FACEBOOK, query, SEARCH) |
| 2306 | if isinstance(query, FacebookResult): |
| 2307 | query = query.id |
| 2308 | # 1) Construct request URL. |
| 2309 | if type == SEARCH: |
| 2310 | url = FACEBOOK + type |
| 2311 | url = URL(url, method=GET, query={ |
| 2312 | "q": query, |
| 2313 | "type": "post", |
| 2314 | "fields": ",".join(("id", "link", "message", "created_time", "from")), |
| 2315 | "offset": (start-1) * min(count, max), |
| 2316 | "limit": (start-0) * min(count, max), |
| 2317 | }) |
| 2318 | if type in (NEWS, FEED, COMMENTS, LIKES, FRIENDS): |
| 2319 | url = FACEBOOK + (u(query) or "me").replace(FACEBOOK, "") + "/" + type.replace("news", "feed") |
| 2320 | url = URL(url, method=GET, query={ |
| 2321 | "access_token": self.license, |
| 2322 | "offset": (start-1) * min(count, max), |
| 2323 | "limit": (start-0) * min(count, max) |
| 2324 | }) |
| 2325 | # 2) Parse JSON response. |
| 2326 | kwargs.setdefault("cached", cached) |
| 2327 | kwargs.setdefault("unicode", True) |
| 2328 | kwargs.setdefault("throttle", self.throttle) |
| 2329 | try: |
| 2330 | data = URL(url).download(**kwargs) |
| 2331 | except HTTP400BadRequest: |
| 2332 | raise HTTP401Authentication |
| 2333 | data = json.loads(data) |
| 2334 | results = Results(FACEBOOK, query, SEARCH) |
| 2335 | results.total = None |
| 2336 | for x in data.get("data", []): |
| 2337 | r = FacebookResult(url=None) |
| 2338 | r.id = self.format(x.get("id")) |
| 2339 | r.url = self.format(x.get("link")) |
| 2340 | r.text = self.format(x.get("story", x.get("message"))) |
nothing calls this directly
no test coverage detected