facebook-sdk
facebook-sdk copied to clipboard
Rename id param in get_object() to object_id
In order to specify 'id' as a keyword argument, we cannot use 'id' as a positional argument name.
This is a fix for: https://github.com/pythonforfacebook/facebook-sdk/issues/197
get_object
does not take keyword arguments, so I don't think this pull request actually solves the problem.
In the issue you opened, you mentioned graph.get_object('comments', id='https://example.com')
as an example of code that fails. Can you describe what you are trying to do?
The method is:
def get_object(self, id, **args)
....
return self.request(self.version + "/", args)
So as is it definitely takes in keyword arguments. I assumed this was so that you could pass in keyword arguments to finally get them to go through requests.request()
inside of self.request()
as the URL parameters?
In the line I posted that fails: graph.get_object('comments', id='https://example.com')
, what that line should be doing is getting all of the comments for the graph object that is associated with the given url.
I'm in a situation where all I have is a URL, and I'm trying to find the comments associated with it.
I think you want to do graph.get_connections("https://example.com", "comments")
. In the Graph API, comments are an "edge" (previously called a connection), not a "node" (an object).
Let me know if I am missing something, or if there is another object/node in the API that uses "id" as a parameter.
Actually, my FB Graph query is slightly incorrect, but the same issue still holds.
Technically the breaking line would be:
graph.get_object('', id='http://example.com', fields='og_object{comments}')
Note: this is for v2.1+
The comments are not traditional comments, they're via this: https://developers.facebook.com/docs/plugins/comments. Near the end of the page is a section describing how to retrieve the comments, you need to get to this endpoint:
https://graph.facebook.com/v2.1/?fields=og_object{comments}&id=<YOUR_URL>&access_token=<YOUR_TOKEN>
But even with that specific use case aside, you can still query the graph like so:
https://graph.facebook.com/v2.0/?id=http%3A%2F%2Fexample.com&access_token=<YOUR_TOKEN>
which would translate to:
graph.get_object('', id='http://example.com')
and is currently broken.
Does graph.get_object('', id='http://example.com')
differ from graph.get_object(id="http://example.com")
?
Would graph.get_object("http://example.com", fields="og_object{comments}")
return similar results, or is accessing comments and other data from the URL node limited to ?id=
syntax?
Regardless, I think moving away from using Python built-ins as variable names is a good idea.
The documentation is surprisingly poor, but yes, everything I've found to date has shown that graph.get_object('', id='http://example.com')
is not the same as graph.get_object(id="http://example.com")
.
If you had the url id
you could do graph.facebook.com/v2.0/url_id
, but with only the actual url, you have to do graph.facebook.com/v2.0/?id=actual_url
.
Any chance you would be willing to write a unit test for this?
Sure!
Done.
Updated.
+1
When is 2.0.0 planned to be released?