facebook-sdk icon indicating copy to clipboard operation
facebook-sdk copied to clipboard

Rename id param in get_object() to object_id

Open dursk opened this issue 9 years ago • 12 comments

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

dursk avatar Feb 26 '15 20:02 dursk

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?

martey avatar Feb 26 '15 21:02 martey

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.

dursk avatar Feb 26 '15 21:02 dursk

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.

martey avatar Feb 26 '15 21:02 martey

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+

dursk avatar Feb 26 '15 21:02 dursk

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.

dursk avatar Feb 26 '15 21:02 dursk

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.

martey avatar Feb 26 '15 22:02 martey

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.

dursk avatar Feb 26 '15 22:02 dursk

Any chance you would be willing to write a unit test for this?

martey avatar Feb 27 '15 01:02 martey

Sure!

dursk avatar Feb 27 '15 19:02 dursk

Done.

dursk avatar Mar 01 '15 03:03 dursk

Updated.

dursk avatar Mar 02 '15 20:03 dursk

+1

When is 2.0.0 planned to be released?

k-funk avatar Jun 05 '16 01:06 k-funk