【发布时间】:2019-12-01 06:04:11
【问题描述】:
提前非常感谢您。我正在尝试通过slack_authentication 获取用户个人资料信息。尽管该应用已成功通过 Slack 身份验证,但它无法获取 电子邮件 和 用户名。
{'ok': True, 'access_token': 'xoxp-xXXXXXXXXXXXXXXXX', 'scope': 'identify,channels:read,users.profile:read,chat:write:bot,identity.basic', 'user_id ':'XXXXXXXXX','team_id':'XXXXXXXX','enterprise_id':无,'team_name':'test','warning':'superfluous_charset','response_metadata':{'warnings':['superfluous_charset'] }}
我尝试添加 identify 范围而不是 identity.basic,因为 slack 不允许您同时使用 identity.basic 和其他范围。
代码如下:
@bp.route('/redirect', methods=['GET'])
def authorize():
authorize_url = f"https://slack.com/oauth/authorize?scope={ oauth_scope }&client_id={ client_id }"
return authorize_url
@bp.route('/callback', methods=["GET", "POST"])
def callback():
auth_code = request.args['code']
client = slack.WebClient(token="")
response = client.oauth_access(
client_id=client_id,
client_secret=client_secret,
code=auth_code
)
print(response)
附加
我已经知道如何获取users info。我将代码更新为这样。
代码更新如下:
oauth = client.oauth_access(
client_id=client_id,
client_secret=client_secret,
code=auth_code
)
user_id = oauth['user_id']
response = client.users_info(user=user_id)
但是出现这个错误:
服务器响应:{'ok': False, 'error': 'not_authed'}
【问题讨论】: