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

Rename id param in get_object() to object_id #198

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

dursk
Copy link

@dursk dursk commented Feb 26, 2015

In order to specify 'id' as a keyword argument,
we cannot use 'id' as a positional argument name.

This is a fix for: #197

In order to specify 'id' as a keyword argument,
we cannot use 'id' as a positional argument name.
@martey
Copy link
Member

martey commented Feb 26, 2015

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?

@dursk
Copy link
Author

dursk commented Feb 26, 2015

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.

@martey
Copy link
Member

martey commented Feb 26, 2015

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.

@dursk
Copy link
Author

dursk commented Feb 26, 2015

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
Copy link
Author

dursk commented Feb 26, 2015

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.

@martey
Copy link
Member

martey commented Feb 26, 2015

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.

@dursk
Copy link
Author

dursk commented Feb 26, 2015

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.

@martey
Copy link
Member

martey commented Feb 27, 2015

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

@dursk
Copy link
Author

dursk commented Feb 27, 2015

Sure!

@dursk
Copy link
Author

dursk commented Mar 1, 2015

Done.

class TestGetObject(FacebookTestCase):
def test_get_object(self):
# The value we are passing as 'fields' is valid only in 2.1+.
graph = facebook.GraphAPI(access_token=facebook.get_app_access_token(
Copy link
Member

Choose a reason for hiding this comment

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

facebook.get_app_access_token is deprecated and might be removed in the near future. Can we use the GraphAPI().get_app_access_token here?

Copy link
Author

Choose a reason for hiding this comment

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

Done. My bad on that, I followed the same pattern as a test above it which I guess hasn't been updated yet.

@dursk
Copy link
Author

dursk commented Mar 2, 2015

Updated.

@martey martey added this to the v2.0.0 milestone Sep 29, 2015
@k-funk
Copy link
Contributor

k-funk commented Jun 5, 2016

+1

When is 2.0.0 planned to be released?

@martey martey modified the milestones: v3.0.0, v2.0.0 Aug 8, 2016
@martey martey modified the milestones: v3.0.0, v4.0.0 Jul 19, 2018
@martey martey modified the milestones: v4.0.0, v5.0.0 Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants