Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ You can initialize a ``GraphAPI`` object with three different methods, depending
# ('https://www.facebook.com/dialog/oauth?response_type=code&client_id=id&redirect_uri=https%3A%2F%2Flocalhost%2F&scope=public_profile&state=PyFacebook', 'PyFacebook')
# let user to do oauth at the browser opened by link.
# then get the response url
>>> api.exchange_user_access_token(response="url redirected")
>>> await api.exchange_user_access_token(response="url redirected")
# Now the api will get the user access token.

For more info about the different access tokens, see https://developers.facebook.com/docs/facebook-login/guides/access-tokens.

Once you have the user access token, you can get the Facebook data. For example,

>>> api.get_object(object_id="20531316728")
>>> await api.get_object(object_id="20531316728")
>>> {'name': 'Facebook App', 'id': '20531316728'}

See the code for more operations.
Expand All @@ -97,12 +97,12 @@ FacebookAPI

To get the user data::

>>> fb.user.get_info(user_id="413140042878187")
>>> await fb.user.get_info(user_id="413140042878187")
>>> User(id='413140042878187', name='Kun Liu')

To get the page data::

>>> fb.page.get_info(page_id="20531316728")
>>> await fb.page.get_info(page_id="20531316728")
>>> Page(id='20531316728', name='Facebook App')

For more info, please, see the code or the docs.
Expand Down
12 changes: 6 additions & 6 deletions docs/docs/usage/graph-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,43 @@ After initial API. Now we can access facebook api with this API.
You can get data of an object, such as page,post,photo and so on.

```python
api.get_object(object_id="108824017345866")
await api.get_object(object_id="108824017345866")
# {'name': 'Meta', 'id': '108824017345866'}
```

You can get the data of some objects.

```python
api.get_objects(ids="108824017345866,20531316728")
await api.get_objects(ids="108824017345866,20531316728")
# {'108824017345866': {'name': 'Meta', 'id': '108824017345866'}, '20531316728': {'name': 'Facebook App', 'id': '20531316728'}}
```

If you want to get data for an object's edge. For example, a User node can have photos connected to it, and a Photo node
can have comments connected to it.

```python
api.get_connection(object_id="20531316728", connection="posts")
await api.get_connection(object_id="20531316728", connection="posts")
# {'data': [{'created_time': '2021-11-26T20:01:40+0000', 'message': "Do Black Friday right with the #BuyBlack Friday Show! For the finale, host Elaine Welteroth will be talking with Sir Darius Brown, the owner of Beaux and Paws. We'll also have special guests D-Nice, Iddris Sandu., and Jaden Smith! Join this fun shop-a-thon in partnership with Meta for Business \n\nShop directly on [Beaux and Paws] Facebook page so you can get your pet looking proper. fb.me/buyblackfri", 'story': 'Facebook App was live.', 'id': '20531316728_3789869301238646'}], 'paging': {'cursors': {'before': 'before', 'after': 'after'}, 'next': 'https://graph.facebook.com/v12.0/20531316728/posts?access_token=access_token&limit=1&after=after'}}
```

If you want to get all data for an object's edge. Auto paging inside.

```python
api.get_full_connections(object_id="20531316728", connection="posts")
await api.get_full_connections(object_id="20531316728", connection="posts")
# {'data': [{'created_time': '2021-11-26T20:01:40+0000', 'message': "Do Black Friday right with the #BuyBlack Friday Show! For the finale, host Elaine Welteroth will be talking with Sir Darius Brown, the owner of Beaux and Paws. We'll also have special guests D-Nice, Iddris Sandu., and Jaden Smith! Join this fun shop-a-thon in partnership with Meta for Business \n\nShop directly on [Beaux and Paws] Facebook page so you can get your pet looking proper. fb.me/buyblackfri", 'story': 'Facebook App was live.', 'id': '20531316728_3789869301238646'}], 'paging': {'cursors': {'before': 'before', 'after': 'after'}, 'next': 'https://graph.facebook.com/v12.0/20531316728/posts?access_token=access_token&limit=1&after=after'}}
```

If you have permissions to publish data. you can use `post` to create data.

```python
api.post_object(object_id="2121008874780932_404879271158877", connection="comments",
await api.post_object(object_id="2121008874780932_404879271158877", connection="comments",
data={"message": "Comment by the api"})
# {'id': '404879271158877_405046241142180'}
```

If you have permissions to delete data.

```python
api.delete_object(object_id="404879271158877_405046241142180")
await api.delete_object(object_id="404879271158877_405046241142180")
# {'success': True}
```
4 changes: 2 additions & 2 deletions docs/docs/usage/threads-graph-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ api.get_authorization_url()

# Once the user has authorized your app, you will get the redirected URL.
# like `https://example.com/callback?code=AQBZzYhLZB&state=PyFacebook#_`
token = api.exchange_user_access_token(response="Your response url")
token = await api.exchange_user_access_token(response="Your response url")
print(token)
# {'access_token': 'access_token', 'user_id': 12342412}
```
Expand All @@ -37,7 +37,7 @@ After those steps, you can use the `api` object to call the Threads API.
For example:

```python
api.get_object(object_id="me", fields=["id"])
await api.get_object(object_id="me", fields=["id"])

# {'id': '12342412'}
```
4 changes: 2 additions & 2 deletions pyfacebook/api/facebook/common_edges/albums.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class AlbumsEdge:
__slots__ = ()

def get_albums(
async def get_albums(
self,
object_id: str,
fields: Optional[Union[str, list, dict]] = None,
Expand Down Expand Up @@ -43,7 +43,7 @@ def get_albums(
if fields is None:
fields = const.ALBUM_PUBLIC_FIELDS

data = self.client.get_full_connections(
data = await self.client.get_full_connections(
object_id=object_id,
connection="albums",
count=count,
Expand Down
4 changes: 2 additions & 2 deletions pyfacebook/api/facebook/common_edges/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class CommentsEdge:
__slots__ = ()

def get_comments(
async def get_comments(
self,
object_id: str,
fields: Optional[Union[str, list, dict]] = None,
Expand Down Expand Up @@ -50,7 +50,7 @@ def get_comments(
if fields is None:
fields = const.COMMENT_PUBLIC_FIELDS

data = self.client.get_full_connections(
data = await self.client.get_full_connections(
object_id=object_id,
connection="comments",
count=count,
Expand Down
8 changes: 4 additions & 4 deletions pyfacebook/api/facebook/common_edges/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FeedEdge:

__slots__ = ()

def _get_feed(
async def _get_feed(
self,
object_id: str,
fields: Optional[Union[str, list, dict]] = None,
Expand Down Expand Up @@ -49,7 +49,7 @@ def _get_feed(
if fields is None:
fields = const.POST_PUBLIC_FIELDS + const.POST_CONNECTIONS_SUMMERY_FIELDS

data = self.client.get_full_connections(
data = await self.client.get_full_connections(
object_id=object_id,
connection=source,
count=count,
Expand All @@ -64,7 +64,7 @@ def _get_feed(
else:
return FeedResponse.new_from_json_dict(data)

def get_feed(
async def get_feed(
self,
object_id: str,
fields: Optional[Union[str, list, dict]] = None,
Expand All @@ -91,7 +91,7 @@ def get_feed(
:param kwargs: Additional parameters for different object.
:return: Posts response information
"""
return self._get_feed(
return await self._get_feed(
object_id=object_id,
fields=fields,
since=since,
Expand Down
12 changes: 6 additions & 6 deletions pyfacebook/api/facebook/common_edges/likes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class LikesEdge:
__slots__ = ()

def get_likes(
async def get_likes(
self,
object_id: str,
fields: Optional[Union[str, list, dict]] = None,
Expand All @@ -39,7 +39,7 @@ def get_likes(
if fields is None:
fields = const.LIKES_FIELDS

data = self.client.get_connection(
data = await self.client.get_connection(
object_id=object_id,
connection="likes",
fields=enf_comma_separated(field="fields", value=fields),
Expand All @@ -51,27 +51,27 @@ def get_likes(
else:
return LikesResponse.new_from_json_dict(data)

def creat_like(self, object_id: str) -> dict:
async def creat_like(self, object_id: str) -> dict:
"""
Like an object.

:param object_id: ID the facebook object.
:return: status for the operation.
"""
data = self.client.post_object(
data = await self.client.post_object(
object_id=object_id,
connection="likes",
)
return data

def delete_like(self, object_id: str) -> dict:
async def delete_like(self, object_id: str) -> dict:
"""
Delete likes on object using this endpoint.

:param object_id: ID the facebook object.
:return: status for the operation.
"""
data = self.client.delete_object(
data = await self.client.delete_object(
object_id=object_id,
connection="likes",
)
Expand Down
4 changes: 2 additions & 2 deletions pyfacebook/api/facebook/common_edges/live_videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class LiveVideosEdge:
__slots__ = ()

def get_live_videos(
async def get_live_videos(
self,
object_id: str,
fields: Optional[Union[str, list, dict]] = None,
Expand Down Expand Up @@ -43,7 +43,7 @@ def get_live_videos(
if fields is None:
fields = const.LIVE_VIDEO_PUBLIC_FIELDS

data = self.client.get_full_connections(
data = await self.client.get_full_connections(
object_id=object_id,
connection="live_videos",
count=count,
Expand Down
4 changes: 2 additions & 2 deletions pyfacebook/api/facebook/common_edges/photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class PhotosEdge:
__slots__ = ()

def get_photos(
async def get_photos(
self,
object_id: str,
fields: Optional[Union[str, list, dict]] = None,
Expand Down Expand Up @@ -43,7 +43,7 @@ def get_photos(
if fields is None:
fields = const.PHOTO_PUBLIC_FIELDS

data = self.client.get_full_connections(
data = await self.client.get_full_connections(
object_id=object_id,
connection="photos",
count=count,
Expand Down
4 changes: 2 additions & 2 deletions pyfacebook/api/facebook/common_edges/videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class VideosEdge:
__slots__ = ()

def get_videos(
async def get_videos(
self,
object_id: str,
fields: Optional[Union[str, list, dict]] = None,
Expand Down Expand Up @@ -43,7 +43,7 @@ def get_videos(
if fields is None:
fields = const.VIDEO_PUBLIC_FIELDS

data = self.client.get_full_connections(
data = await self.client.get_full_connections(
object_id=object_id,
connection="videos",
count=count,
Expand Down
8 changes: 4 additions & 4 deletions pyfacebook/api/facebook/resource/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


class FacebookAlbum(BaseResource, PhotosEdge, LikesEdge):
def get_info(
async def get_info(
self,
album_id: Optional[str],
fields: Optional[Union[str, list, tuple]] = None,
Expand All @@ -32,7 +32,7 @@ def get_info(
if fields is None:
fields = const.ALBUM_PUBLIC_FIELDS

data = self.client.get_object(
data = await self.client.get_object(
object_id=album_id,
fields=enf_comma_separated(field="fields", value=fields),
)
Expand All @@ -41,7 +41,7 @@ def get_info(
else:
return Album.new_from_json_dict(data=data)

def get_batch(
async def get_batch(
self,
ids: Optional[Union[str, list, tuple]],
fields: Optional[Union[str, list, tuple]] = None,
Expand All @@ -62,7 +62,7 @@ def get_batch(
if fields is None:
fields = const.PHOTO_PUBLIC_FIELDS

data = self.client.get_objects(
data = await self.client.get_objects(
ids=ids,
fields=enf_comma_separated(field="fields", value=fields),
)
Expand Down
8 changes: 4 additions & 4 deletions pyfacebook/api/facebook/resource/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class FacebookApplication(BaseResource):
def get_info(
async def get_info(
self,
fields: Optional[Union[str, list, tuple]] = None,
return_json: bool = False,
Expand All @@ -28,7 +28,7 @@ def get_info(
if fields is None:
fields = const.APPLICATION_PUBLIC_FIELDS

data = self.client.get_object(
data = await self.client.get_object(
object_id=self.client.app_id,
fields=enf_comma_separated(field="fields", value=fields),
)
Expand All @@ -37,7 +37,7 @@ def get_info(
else:
return Application.new_from_json_dict(data=data)

def get_accounts(
async def get_accounts(
self,
fields: Optional[Union[str, list, dict]] = None,
count: Optional[int] = 10,
Expand All @@ -60,7 +60,7 @@ def get_accounts(
if fields is None:
fields = const.APPLICATION_ACCOUNT_PUBLIC_FIELDS

data = self.client.get_full_connections(
data = await self.client.get_full_connections(
object_id=self.client.app_id,
connection="accounts",
count=count,
Expand Down
8 changes: 4 additions & 4 deletions pyfacebook/api/facebook/resource/business.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class FacebookBusiness(BaseResource):
def get_info(
async def get_info(
self,
business_id: str,
fields: Optional[Union[str, list, tuple]] = None,
Expand All @@ -30,7 +30,7 @@ def get_info(
if fields is None:
fields = const.BUSINESS_PUBLIC_FIELDS

data = self.client.get_object(
data = await self.client.get_object(
object_id=business_id,
fields=enf_comma_separated(field="fields", value=fields),
)
Expand All @@ -39,7 +39,7 @@ def get_info(
else:
return Business.new_from_json_dict(data=data)

def get_batch(
async def get_batch(
self,
ids: Union[str, list, tuple],
fields: Optional[Union[str, list, tuple]] = None,
Expand All @@ -60,7 +60,7 @@ def get_batch(
if fields is None:
fields = const.BUSINESS_PUBLIC_FIELDS

data = self.client.get_objects(
data = await self.client.get_objects(
ids=ids,
fields=enf_comma_separated(field="fields", value=fields),
)
Expand Down
Loading