sns-sdks / python-facebook

A simple Python wrapper for facebook graph api :sparkles: :cake: :sparkles: .
https://sns-sdks.github.io/python-facebook/
322 stars 84 forks source link

Missing description for method `GraphAPI.exchange_user_access_token` #238

Open nbro10 opened 10 months ago

nbro10 commented 10 months ago

Currently,

    def exchange_user_access_token(
        self,
        response: str,
        redirect_uri: Optional[str] = None,
        scope: Optional[List[str]] = None,
        **kwargs,
    ) -> dict:
        """
        :param response: The redirect response url for authorize redirect
        :param scope: A list of permission string to request from the person using your app.
        :param redirect_uri: Url for your redirect.
        :param kwargs: Additional parameters for oauth.
        :return:
        """

So, we have only a description of the parameters. This a public method, so it should have a description

MerleLiuKun commented 10 months ago

Yes , you are right. We can add description for this, And other method.

nbro10 commented 5 months ago

@MerleLiuKun I think this method should also provide the possibility to generate the user access token given the authorization code or maybe there should be another method for that case.

Here, the response parameter is unclear to me. The docstrings says The redirect response url for authorize redirect, but this is a bit unclear to me. Where would we get this URL if usually what you get is an authorization code, when the user gives you permission? I suppose you would need to build this URL. Can you clarify what response is here?

MerleLiuKun commented 5 months ago

the reponse is a url, it is generated by facebook.

When you generate a ouath url to let user operate. After user give permisson, Facebook will direct to the redirect url you have pointed at oauth url.

The direct url is the reponse

nbro10 commented 5 months ago

@MerleLiuKun Alright, but isn't this URL just the redirect URI that you pass to api.get_authorization_url with the authorization code and the state? In that case, one can automatically build the this URL from what api.get_authorization_url returns. In my case, I actually get only the authorization code and the URL is in the browser, so I'd need to copy either the browser's URL or copy the authorization code and then build the URL. That's why I think this method should also accept the authorization code and state and be able to do the same job. Anyway, this parameter response should be renamed to something like redirect_url.

MerleLiuKun commented 5 months ago

Yes you are right. But we think this is facebook's reponse. just style is a url

kathanpatel0901 commented 3 months ago

but when we pass response url to exchange_user_access_token they gives encode error

response_url = request.build_absolute_uri()
    print("RESPONSE URL:", response_url)
    access_token = API.exchange_user_access_token(
        response=response_url, redirect_uri=FREDIRECT_URL
    )

error:'OAuth2Token' object has no attribute 'encode'

MerleLiuKun commented 3 months ago

Could you give more information? I have not seen this error.