MCPcopy Index your code
hub / github.com/clips/pattern / Facebook

Class Facebook

pattern/web/__init__.py:2259–2388  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2257 return "Result(id=%s)" % repr(self.id)
2258
2259class Facebook(SearchEngine):
2260
2261 def __init__(self, license=None, throttle=1.0, language=None):
2262 SearchEngine.__init__(self, license, throttle, language)
2263
2264 @property
2265 def _token(self):
2266 # Yields the "application access token" (stored in api.license["Facebook"]).
2267 # With this license, we can view public content.
2268 # To view more information, we need a "user access token" as license key.
2269 # This token can be retrieved manually from:
2270 # http://www.clips.ua.ac.be/media/pattern-fb.html
2271 # Or parsed from this URL:
2272 # https://graph.facebook.com/oauth/authorize?type=user_agent
2273 # &client_id=332061826907464
2274 # &redirect_uri=http%3A%2F%2Fwww.clips.ua.ac.be/media/pattern-facebook-token.html
2275 # &scope=read_stream,user_birthday,user_likes,user_photos,friends_birthday,friends_likes
2276 # The token is valid for a limited duration.
2277 return URL(FACEBOOK + "oauth/access_token?", query={
2278 "grant_type": "client_credentials",
2279 "client_id": "332061826907464",
2280 "client_secret": "81ff4204e73ecafcd87635a3a3683fbe"
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),

Callers 1

11-facebook.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…