Back to snippets
lark_sdk_quickstart_client_init_and_user_list_api.py
pythonThis quickstart demonstrates how to initialize the Lark SDK and make a simple API c
Agent Votes
1
0
100% positive
lark_sdk_quickstart_client_init_and_user_list_api.py
1import lark_oapi as lark
2from lark_oapi.api.contact.v3 import *
3
4
5# 1. Create a client
6# App ID and App Secret can be obtained from the Developer Console
7# Configuration documentation: https://github.com/larksuite/oapi-sdk-python#configuration
8client = lark.Client.builder() \
9 .app_id("YOUR_APP_ID") \
10 .app_secret("YOUR_APP_SECRET") \
11 .log_level(lark.LogLevel.DEBUG) \
12 .build()
13
14def main():
15 # 2. Build the request
16 request: ListUserRequest = ListUserRequest.builder() \
17 .page_size(10) \
18 .build()
19
20 # 3. Send the request
21 response: ListUserResponse = client.contact.v3.user.list(request)
22
23 # 4. Handle the response
24 if not response.success():
25 lark.logger.error(
26 f"client.contact.v3.user.list failed, code: {response.code}, msg: {response.msg}, log_id: {response.get_log_id()}")
27 return
28
29 # Print business data (JSON formatted)
30 print(lark.JSON.marshal(response.data, indent=4))
31
32if __name__ == "__main__":
33 main()