From 54dc51939495c7f7b4cc038cfac9e288e3bc18ff Mon Sep 17 00:00:00 2001 From: Marcellus Amadeus <7marcellus@gmail.com> Date: Sat, 18 Feb 2017 15:46:07 -0200 Subject: [PATCH 1/2] Add support for post_args on GraphAPI.put_object() --- facebook/__init__.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/facebook/__init__.py b/facebook/__init__.py index eb8dd6a6..2c60932f 100755 --- a/facebook/__init__.py +++ b/facebook/__init__.py @@ -143,29 +143,42 @@ def get_all_connections(self, id, connection_name, **args): args = parse_qs(urlparse(next).query) del args['access_token'] - def put_object(self, parent_object, connection_name, **data): + def put_object(self, parent_object, connection_name, post_args=None, **data): """Writes the given object to the graph, connected to the given parent. - For example, - graph.put_object("me", "feed", message="Hello, world") - writes "Hello, world" to the active user's wall. Likewise, this will comment on the first post of the active user's feed: - feed = graph.get_connections("me", "feed") post = feed["data"][0] graph.put_object(post["id"], "comments", message="First!") - + Some parameters that can be sent to the Facebook API can not be passed + to the method using kwargs, for example 'fb:explicitly_shared'. These + needs to be set using the post_args argument dict. If the same key is + used both in the post_arg dict and passed in as a kwarg, the kwarg will + take precedence. + Usage example, + graph.put_object( + "me", + "nyccookbook:cook", + recipe="http://www.sugarmedia.com/nyccookbook/cookie.html", + post_args={"fb:explicitly_shared": True} + ) + will share the object as a post as described in the docs. See + https://developers.facebook.com/docs/opengraph/guides/explicit-sharing/ + for details. Certain operations require extended permissions. See https://developers.facebook.com/docs/facebook-login/permissions for details about permissions. - """ assert self.access_token, "Write operations require an access token" + if post_args is None: + post_args = {} + post_args.update(data) + return self.request( "{0}/{1}/{2}".format(self.version, parent_object, connection_name), - post_args=data, + post_args=post_args, method="POST") def put_wall_post(self, message, attachment={}, profile_id="me"): From 09313edb4b3072d95c19e5fd7ca501d8e5f9c33c Mon Sep 17 00:00:00 2001 From: Marcellus Amadeus <7marcellus@gmail.com> Date: Sat, 18 Feb 2017 15:58:06 -0200 Subject: [PATCH 2/2] Reduce line length on put_object (flake8 E501) --- facebook/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/facebook/__init__.py b/facebook/__init__.py index 2c60932f..0d59907b 100755 --- a/facebook/__init__.py +++ b/facebook/__init__.py @@ -143,7 +143,8 @@ def get_all_connections(self, id, connection_name, **args): args = parse_qs(urlparse(next).query) del args['access_token'] - def put_object(self, parent_object, connection_name, post_args=None, **data): + def put_object( + self, parent_object, connection_name,post_args=None, **data): """Writes the given object to the graph, connected to the given parent. For example, graph.put_object("me", "feed", message="Hello, world")