Dash Plotly - 如何重定向到将重定向到 Dash 的外部链接

问题描述

我正在使用 Fitbit 的 api 和 Dash Plotly。

我正在尝试获取 Fitbit 的 access_token,您可以通过访问此 URL 获取

"https://www.fitbit.com/oauth2/authorize?response_type=token&client_id={FITBIT_CLIENT_ID}&redirect_uri=http%3A%2F%2F127.0.0.1%3A8050%2F&scope=activity%20heartrate%20location%20nutrition%20profile%20settings%20sleep%20social%20weight&expires_in=604800"

此 URL 将重定向http://127.0.0.1:8050/,URL 末尾带有代码 http://127.0.0.1:8050/#access_token=....

我正在尝试通过 Dash 获得 access_token

问题:

  • 重定向有效并提供访问令牌,但以使用 dcc.Location(id="auth_url",refresh=True href=authorization_url,)
  • 的无限循环结束
  • 使用回调将 refresh 内的 dcc.Location 属性切换为 False 似乎不起作用。
  • 使用 if "access_token=" in pathname: 似乎无法捕获地址栏中的路径名 print (pathname) 打印 "/" 尽管地址栏的 URL 包含代码

代码

def auth():
return html.Div(
        dcc.Location(id="auth_url",href=authorization_url,refresh=True)
        )


@app.callback(
    Output("auth_url","refresh"),Input("auth_url","pathname")
)
def callback(pathname):
    print (pathname)
    if "access_token" in pathname:
        return False

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)