Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for post_args on GraphAPI.put_object method (PR #108 update) #344

Closed
wants to merge 2 commits into from
Closed
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
30 changes: 22 additions & 8 deletions facebook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,29 +143,43 @@ 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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a PEP8 issue on this line that is causing the linting test to fail.

"""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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were these lines removed?

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"):
Expand Down