Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

python - 无法通过API获取松弛的用户个人资料信息(Can't fetch slack user profile information with API)

Thank you so much in advance.

(提前非常感谢您。)

I am trying to fetch user profile information through slack_authentication .

(我正在尝试通过slack_authentication获取用户配置文件信息。)

Although the app is successfully authenticated with Slack, it could not get email and username .

(尽管该应用已通过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': None, 'team_name': 'test', 'warning': 'superfluous_charset', 'response_metadata': {'warnings': ['superfluous_charset']}}

({'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']}})

I tried to add identify scope instead of identity.basic because slack doesn't allow you to use both identity.basic and other scopes.

(我尝试添加identify范围而不是identity.basic因为松弛不允许您同时使用identity.basic和其他范围。)

The code is below:

(代码如下:)

@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)
  ask by k10a translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your code looks like an installation routine for a Slack app using OAuth.

(您的代码看起来像是使用OAuth的Slack应用程序的安装例程。)

But it does not contain a call to get a user profile.

(但是它不包含获取用户个人资料的调用。)

To get the profile of a user you can call users.info and provide the ID of the user you are interested in.

(要获取用户的个人资料,您可以调用users.info并提供您感兴趣的用户的ID。)

Examples:

(例子:)

response = client.users_info(user=ID_OF_USER)
assert(response)
profile = response['user']['profile']
email = response['user']['profile']['email']

In order to retrieve the user's profile and email address you need these scopes: - users:read - users:read.email

(为了检索用户的个人资料和电子邮件地址,您需要以下范围:-users:read-users:read.email)

The identity scopes are unrelated to the user profile.

(身份范围与用户配置文件无关。)

They are used for the " Sign-in with Slack " approach only, where you can authenticate with a Slack user on a 3rd party web site.

(它们仅用于“ 使用Slack登录 ”方法,您可以在其中通过第三方网站上的Slack用户进行身份验证。)

Finally, just to clarify, because this is often misunderstood: You only need to run through the OAuth installation routine once.

(最后,只需澄清一下,因为这常常被误解:您只需要运行一次OAuth安装例程。)

The routine will yield you a token for the workspace, which you can store and use for any further calls to the API for that workspace.

(该例程将为您提供工作空间的令牌,您可以将其存储并用于对该工作空间的API的任何其他调用。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...