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

Missing description for method `GraphAPI.exchange_user_access_token`

Open nbro10 opened this issue 2 years ago • 7 comments

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

nbro10 avatar Sep 01 '23 11:09 nbro10

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

MerleLiuKun avatar Sep 19 '23 10:09 MerleLiuKun

@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?

nbro10 avatar Jan 31 '24 09:01 nbro10

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

MerleLiuKun avatar Jan 31 '24 09:01 MerleLiuKun

@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.

nbro10 avatar Jan 31 '24 10:01 nbro10

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

MerleLiuKun avatar Feb 01 '24 02:02 MerleLiuKun

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'

kathanpatel0901 avatar Apr 04 '24 20:04 kathanpatel0901

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

MerleLiuKun avatar Apr 08 '24 02:04 MerleLiuKun