forked from sns-sdks/python-facebook
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfeed.py
More file actions
103 lines (92 loc) · 3.73 KB
/
feed.py
File metadata and controls
103 lines (92 loc) · 3.73 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
"""
Feed edge for resource.
"""
from typing import Optional, Union
import pyfacebook.utils.constant as const
from pyfacebook.models.post import FeedResponse
from pyfacebook.utils.params_utils import enf_comma_separated
class FeedEdge:
"""
Base resource for object with feed
"""
__slots__ = ()
def _get_feed(
self,
object_id: str,
fields: Optional[Union[str, list, dict]] = None,
since: Optional[str] = None,
until: Optional[str] = None,
count: Optional[int] = 10,
limit: Optional[int] = 10,
source: Optional[str] = "feed",
return_json: bool = False,
**kwargs,
) -> Union[FeedResponse, dict]:
"""
Get feed of a Facebook object.
:param object_id: ID for object to get feeds.
:param fields: Comma-separated id string for data fields which you want.
You can also pass this with an id list, tuple.
:param since: A Unix timestamp or strtotime data value that points to the start of data.
:param until: A Unix timestamp or strtotime data value that points to the end of data.
:param count: The total count for you to get data.
:param limit: Each request retrieve objects count.
It should no more than 100. Default is None will use api default limit.
:param source: Resource type. Valid values maybe feed/posts/tagged/published_posts depend on object type.
:param return_json: Set to false will return a dataclass for post.
Or return json data. Default is false.
:param kwargs: Additional parameters for different object.
:return: feed response information
"""
if fields is None:
fields = const.POST_PUBLIC_FIELDS + const.POST_CONNECTIONS_SUMMERY_FIELDS
data = self.client.get_full_connections(
object_id=object_id,
connection=source,
count=count,
limit=limit,
fields=enf_comma_separated(field="fields", value=fields),
since=since,
until=until,
**kwargs,
)
if return_json:
return data
else:
return FeedResponse.new_from_json_dict(data)
def get_feed(
self,
object_id: str,
fields: Optional[Union[str, list, dict]] = None,
since: Optional[str] = None,
until: Optional[str] = None,
count: Optional[int] = 10,
limit: Optional[int] = 10,
return_json: bool = False,
**kwargs,
) -> Union[FeedResponse, dict]:
"""
Get feed of a Facebook Page including posts and links published by this Page, or by visitors to this Page.
:param object_id: ID for page to get feeds.
:param fields: Comma-separated id string for data fields which you want.
You can also pass this with an id list, tuple.
:param since: A Unix timestamp or strtotime data value that points to the start of data.
:param until: A Unix timestamp or strtotime data value that points to the end of data.
:param count: The total count for you to get data.
:param limit: Each request retrieve objects count.
It should no more than 100. Default is None will use api default limit.
:param return_json: Set to false will return a dataclass for post.
Or return json data. Default is false.
:param kwargs: Additional parameters for different object.
:return: Posts response information
"""
return self._get_feed(
object_id=object_id,
fields=fields,
since=since,
until=until,
count=count,
limit=limit,
return_json=return_json,
**kwargs,
)