【问题标题】:Linkedin API - Bad Redirect, invalid redirect URILinkedin API - 重定向错误,重定向 URI 无效
【发布时间】:2018-08-14 19:46:56
【问题描述】:

我正在将此代码与我的客户端 ID 和客户端密码一起使用:

https://github.com/DEKHTIARJonathan/python3-linkedin/blob/master/examples/oauth2_authentication.py

但是,当在命令行中获取 URL 并将其放入浏览器时,我得到“无效的 redirect_uri。此值必须与使用 API 密钥注册的 URL 匹配。”

我已经使用重定向网址注册了以下内容以尝试使其正常工作:

http://localhost:8080/code
https://localhost:8080/code/
http://localhost:8080/code/signin-linkedin
https://localhost:8080/code/signin-linkedin
https%3A//locahost%3A8080/code/

signin-linkedin 片段来自这里:

linkedin : Invalid redirect_uri. This value must match a URL registered with the API Key

但是,添加最后一个 'sigin-linkedin' 部分并不能缓解问题。

这是我要返回的 URL,# 代替我的 client_id:

https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=##########&scope=r_basicprofile%20r_emailaddress%20rw_company_admin%20w_share&state=04377850f3154ee3f808f762244697b6&redirect_uri=https%3A//locahost%3A8080/code/

提前致谢。

编辑:

我尝试根据其他帖子添加一些额外的网址:

https://appname.auth0.com/login/callback

https://appname.auth0.com

这是我的代码:

if __name__ == '__main__':

    CLIENT_ID = #######
    CLIENT_SECRET = ##########
    RETURN_URL = 'http://localhost:8080/code/'

    authentication = LinkedInAuthentication(
                    CLIENT_ID,
                    CLIENT_SECRET,
                    RETURN_URL,
                    permissions=['r_basicprofile',
                                 'r_emailaddress',
                                 'rw_company_admin',
                                 'w_share']
                )

    print(authentication.authorization_url)
    application = LinkedInApplication(authentication)

【问题讨论】:

    标签: python linkedin linkedin-api


    【解决方案1】:

    您的回调 URL 配置似乎有错误,缺少“l”。

    如果你仔细观察redirect_uri参数,它的值是https%3A//locahost%3A8080/code/,未转义的是https://locahost:8080/code/

    我假设您的意思是要配置为 https://localhost:8080/code/ 的值。

    【讨论】:

    • 嗯,不知道为什么我之前运行它时 l 丢失了,可能是在我尝试其他东西的时候。我把我的代码放在编辑的顶部。我现在将其作为重定向 url 但同样的错误(没有丢失):linkedin.com/uas/oauth2/…
    • 有人解决了吗?我遇到了完全相同的问题
    • 说实话,我已经一年多没有重新审视这个问题了,所以我不确定是否找到了任何解决方案。
    • 有什么解决办法吗?谢谢!
    【解决方案2】:

    redirect_uri 的 URL 编码看起来不正确。

    对我来说,http://localhost:8080/code/ 变成了 http%3A%2F%2Flocalhost%3A8080%2Fcode%2F。

    当它应该是“%2F”时,你正在发送“/”。

    【讨论】:

    • 如果您的重定向 URL 是您在示例中所拥有的,那么您应该按照我在原始答案中发布的那样发送它。然后不应该出现“无效的重定向 URL”错误。 (该错误意味着您发送的不是应用程序设置中列出的 URL。)您可能会收到此错误,因为它被不正确地转义,而不是因为它需要是另一个帖子中的那些 auth0 URL 之一。
    猜你喜欢
    • 2020-10-29
    • 1970-01-01
    • 2019-02-01
    • 2015-09-13
    • 2020-07-16
    • 1970-01-01
    • 2022-08-08
    • 2019-07-02
    • 2014-10-03
    相关资源
    最近更新 更多