领英API - 重定向错误,无效的重定向URI

8
我正在使用我的客户端ID和客户端密钥,代码如下: https://github.com/DEKHTIARJonathan/python3-linkedin/blob/master/examples/oauth2_authentication.py 但是,在命令行中获取url并将其放入浏览器时,我得到了“无效的redirect_uri。此值必须与API密钥注册的URL匹配。”
为了让它正常工作,我已经在注册以下重定向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

然而,添加最后的“signin-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/

提前感谢您的帮助。

编辑:

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

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)
2个回答

3

看起来你的回调URL配置有误,缺失了一个 "l"。

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

我猜你的意思是将该值配置为 https://localhost:8080/code/


说实话,我不确定为什么之前运行时缺少了“l”,可能是当我尝试其他东西时出现的。我在编辑中放入了我的代码。现在我得到了这个重定向URL,但是同样的错误(没有缺少“l”):https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=86rwrgzelmun06&scope=r_basicprofile%20r_emailaddress%20rw_company_admin%20w_share&state=99da200ec6a41c525959f13901d04044&redirect_uri=http%3A//localhost%3A8080/code/ - dasvootz
有人解决了吗?我遇到了完全相同的问题。 - Odisseo
说实话,我已经一年多没有重新审视这个问题了,所以我不确定是否已经找到了任何解决方案。 - dasvootz
有没有解决方案?谢谢! - 2713

1
您的重定向URI的URL编码似乎不正确。
对于我来说,http://localhost:8080/code/ 变成了 http%3A%2F%2Flocalhost%3A8080%2Fcode%2F。
您应该发送"%2F"而不是"/"。

如果您的重定向URL与示例中的相同,则应按照我在原始答案中发布的方式发送它。那么就不应该出现“无效的重定向URL”错误。(该错误意味着您发送的内容不是应用程序设置中列出的URL)。您可能会因为未正确转义而遇到此问题,而不是因为它需要成为另一篇帖子中的那些auth0 URL之一。 - Adam Trachtenberg

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接