Hướng dẫn python-o365 - python-o365
Show
O365 - API Microsoft Graph và Office 365 được thực hiện dễ dàng
Dự án này nhằm mục đích làm cho việc tương tác với Microsoft Graph và Office 365 dễ thực hiện theo cách Pythonic. Truy cập vào email, lịch, danh bạ, OneDrive, v.v ... rất dễ thực hiện theo cách cảm thấy dễ dàng và thẳng thắn về phía trước và cảm thấy đúng với lập trình viên Python dày dạn. Dự án hiện đang được phát triển và duy trì bởi Janscas. Các nhà phát triển cốt lõi
Chúng tôi luôn sẵn sàng cho các yêu cầu kéo mới! Xây dựng lại tài liệu HTML
Ví dụ nhanh về việc gửi tin nhắn:from O365 import Account credentials = ('client_id', 'client_secret') account = Account(credentials) m = account.new_message() m.to.add('') m.subject = 'Testing!' m.body = "George Best quote: I've stopped drinking, but only while I'm asleep." m.send() Tại sao chọn O365?
Dự án này cũng là một nguồn tài nguyên học tập cho chúng tôi. Đây là danh sách các thành ngữ Python không phổ biến được sử dụng trong dự án này:
Những gì tiếp theo là một loại wiki ... Mục lục
Cài đặtCách sử dụng Xác thực Giao thức
Cách sử dụngXác thực Giao thức Lớp tài khoản và mô -đun Hộp thư scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ... Xác thựcGiao thức Lớp tài khoản và mô -đun
Nhiệm vụ
*O365 sẽ tự động làm mới mã thông báo cho bạn trên phương thức xác thực. Mã thông báo làm mới kéo dài 90 ngày nhưng nó được làm mới trên mỗi kết nối để bạn kết nối trong vòng 90 ngày, bạn có thể có quyền truy cập không giới hạn. Lớp @route('/stepone') def auth_step_one(): callback = 'my absolute url to auth_step_two_callback' account = Account(credentials) url, state = account.con.get_authorization_url(requested_scopes=my_scopes, redirect_uri=callback) # the state must be saved somewhere as it will be needed later my_db.store_state(state) # example... return redirect(url) @route('/steptwo') def auth_step_two_callback(): account = Account(credentials) # retreive the state saved in auth_step_one my_saved_state = my_db.get_state() # example... # rebuild the redirect_uri used in auth_step_one callback = 'my absolute url to auth_step_two_callback' result = account.con.request_token(request.url, state=my_saved_state, redirect_uri=callback) # if result is True, then authentication was succesful # and the auth token is stored in the token backend if result: return render_template('auth_complete.html') # else ....6 xử lý xác thực. Xác thực OAuthPhần này được giải thích bằng giao thức Microsoft Graph, gần như giống nhau áp dụng cho API Office 365 REST. Các bước xác thực
Giao diện xác thực khác nhauĐể thực hiện xác thực, về cơ bản, bạn có thể sử dụng các phương pháp khác nhau. Điều sau đây áp dụng cho phương thức xác thực "thay mặt cho người dùng" vì đây là luồng xác thực 2 bước. Đối với phương thức xác thực "Với danh tính của riêng bạn", bạn chỉ có thể sử dụng @route('/stepone') def auth_step_one(): callback = 'my absolute url to auth_step_two_callback' account = Account(credentials) url, state = account.con.get_authorization_url(requested_scopes=my_scopes, redirect_uri=callback) # the state must be saved somewhere as it will be needed later my_db.store_state(state) # example... return redirect(url) @route('/steptwo') def auth_step_two_callback(): account = Account(credentials) # retreive the state saved in auth_step_one my_saved_state = my_db.get_state() # example... # rebuild the redirect_uri used in auth_step_one callback = 'my absolute url to auth_step_two_callback' result = account.con.request_token(request.url, state=my_saved_state, redirect_uri=callback) # if result is True, then authentication was succesful # and the auth token is stored in the token backend if result: return render_template('auth_complete.html') # else ....9 vì nó sẽ không yêu cầu đầu vào bảng điều khiển.
Quyền và phạm vi:QuyềnKhi sử dụng OAuth, bạn tạo một ứng dụng và cho phép một số tài nguyên được người dùng truy cập và sử dụng. Các tài nguyên này được quản lý với quyền. Chúng có thể được ủy quyền (thay mặt cho người dùng) hoặc quyền aplication. Cái trước được sử dụng khi phương thức xác thực là "thay mặt cho người dùng". Một số trong số này yêu cầu sự đồng ý của quản trị viên. Cái sau khi sử dụng phương thức xác thực "với danh tính của riêng bạn". Tất cả những điều này yêu cầu sự đồng ý của quản trị viên. Phạm viPhạm vi chỉ quan trọng khi sử dụng phương thức xác thực "thay mặt cho người dùng".
Người dùng của thư viện này sau đó có thể yêu cầu quyền truy cập vào một hoặc nhiều tài nguyên này bằng cách cung cấp phạm vi cho nhà cung cấp OAuth.
Ví dụ: Ứng dụng của bạn có thể có Lịch.Read, Mail.ReadWrite và Mail.Send quyền, nhưng ứng dụng chỉ có thể yêu cầu quyền truy cập vào Mail.ReadWrite và Mail.Send quyền. Điều này được thực hiện bằng cách cung cấp phạm vi cho phiên bản @route('/stepone') def auth_step_one(): callback = 'my absolute url to auth_step_two_callback' account = Account(credentials) url, state = account.con.get_authorization_url(requested_scopes=my_scopes, redirect_uri=callback) # the state must be saved somewhere as it will be needed later my_db.store_state(state) # example... return redirect(url) @route('/steptwo') def auth_step_two_callback(): account = Account(credentials) # retreive the state saved in auth_step_one my_saved_state = my_db.get_state() # example... # rebuild the redirect_uri used in auth_step_one callback = 'my absolute url to auth_step_two_callback' result = account.con.request_token(request.url, state=my_saved_state, redirect_uri=callback) # if result is True, then authentication was succesful # and the auth token is stored in the token backend if result: return render_template('auth_complete.html') # else ....8 hoặc phương thức @route('/stepone') def auth_step_one(): callback = 'my absolute url to auth_step_two_callback' account = Account(credentials) url, state = account.con.get_authorization_url(requested_scopes=my_scopes, redirect_uri=callback) # the state must be saved somewhere as it will be needed later my_db.store_state(state) # example... return redirect(url) @route('/steptwo') def auth_step_two_callback(): account = Account(credentials) # retreive the state saved in auth_step_one my_saved_state = my_db.get_state() # example... # rebuild the redirect_uri used in auth_step_one callback = 'my absolute url to auth_step_two_callback' result = account.con.request_token(request.url, state=my_saved_state, redirect_uri=callback) # if result is True, then authentication was succesful # and the auth token is stored in the token backend if result: return render_template('auth_complete.html') # else ....9 như vậy: from O365 import Account credentials = ('client_id', 'client_secret') scopes = ['https://graph.microsoft.com/Mail.ReadWrite', 'https://graph.microsoft.com/Mail.Send'] account = Account(credentials, scopes=scopes) account.authenticate() # The latter is exactly the same as passing scopes to the authenticate method like so: # account = Account(credentials) # account.authenticate(scopes=scopes) Thực hiện phạm vi phụ thuộc vào giao thức được sử dụng. Vì vậy, bằng cách sử dụng dữ liệu giao thức, bạn có thể tự động đặt phạm vi cần thiết. Điều này được thực hiện bằng cách sử dụng 'người trợ giúp phạm vi'. Đó là những người trợ giúp nhỏ mà nhóm phạm vi chức năng và trừu tượng mà Procotol đã sử dụng.
Bạn có thể nhận được phạm vi giống như trước khi sử dụng các giao thức và người trợ giúp phạm vi như thế này: protocol_graph = MSGraphProtocol() scopes_graph = protocol.get_scopes_for('message all') # scopes here are: ['https://graph.microsoft.com/Mail.ReadWrite', 'https://graph.microsoft.com/Mail.Send'] account = Account(credentials, scopes=scopes_graph) protocol_office = MSOffice365Protocol() scopes_office = protocol.get_scopes_for('message all') # scopes here are: ['https://outlook.office.com/Mail.ReadWrite', 'https://outlook.office.com/Mail.Send'] account = Account(credentials, scopes=scopes_office)
Lưu trữ mã thông báo:Khi xác thực, bạn sẽ truy xuất mã thông báo OAuth. Nếu bạn không muốn truy cập một lần, bạn sẽ phải lưu trữ mã thông báo ở đâu đó. O365 không đưa ra giả định nào về nơi lưu trữ mã thông báo và cố gắng trừu tượng hóa điều này từ quan điểm sử dụng thư viện. Bạn có thể chọn nơi và cách lưu trữ mã thông báo bằng cách sử dụng phụ trợ mã thông báo thích hợp. Chăm sóc: Mã thông báo truy cập (và làm mới) phải được bảo vệ khỏi người dùng trái phép. Thư viện sẽ gọi (ở các giai đoạn khác nhau), các phương thức phụ trợ mã thông báo để tải và lưu mã thông báo. Phương pháp tải mã thông báo:
Phương pháp lưu trữ mã thông báo:
Để lưu trữ mã thông báo, bạn sẽ phải cung cấp một tokenbackend được cấu hình đúng. Trên thực tế, chỉ có hai lần thực hiện (nhưng bạn có thể dễ dàng thực hiện nhiều hơn như CookieBackend, Redisbackend, v.v.):
Ví dụ: sử dụng phụ trợ mã thông báo hệ thống tập tin: from O365 import Account, FileSystemTokenBackend credentials = ('id', 'secret') # this will store the token under: "my_project_folder/my_folder/my_token.txt". # you can pass strings to token_path or Path instances from pathlib token_backend = FileSystemTokenBackend(token_path='my_folder', token_filename='my_token.txt') account = Account(credentials, token_backend=token_backend) # This account instance tokens will be stored on the token_backend configured before. # You don't have to do anything more # ... Và bây giờ sử dụng cùng một ví dụ bằng cách sử dụng FirestoretokenBackend: scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...0 Để thực hiện một mã thông báo mới:
Phương pháp from O365 import Account, FileSystemTokenBackend credentials = ('id', 'secret') # this will store the token under: "my_project_folder/my_folder/my_token.txt". # you can pass strings to token_path or Path instances from pathlib token_backend = FileSystemTokenBackend(token_path='my_folder', token_filename='my_token.txt') account = Account(credentials, token_backend=token_backend) # This account instance tokens will be stored on the token_backend configured before. # You don't have to do anything more # ...8 được dự định sẽ được triển khai cho các môi trường nơi nhiều trường hợp kết nối đang chạy trên Paralel. Phương pháp này nên kiểm tra xem có phải là lúc để làm mới mã thông báo hay không. Phần phụ trợ được chọn có thể lưu trữ một lá cờ ở đâu đó để trả lời câu hỏi này. Điều này có thể tránh các điều kiện chủng tộc giữa các trường hợp khác nhau cố gắng làm mới mã thông báo cùng một lúc, khi chỉ có một người nên làm mới. Phương thức sẽ trả về ba giá trị có thể thực hiện:
Theo mặc định, điều này luôn trả về đúng vì nó đang hoạt động, không có kết nối song song nào chạy cùng một lúc. Có hai ví dụ về phương pháp này trong thư mục ví dụ ở đây. Giao thứcCác giao thức xử lý các khía cạnh của giao tiếp giữa các API khác nhau. Dự án này sử dụng API Microsoft Graph (theo mặc định) hoặc API Office 365. Nhưng, bạn có thể sử dụng nhiều API Microsoft khác miễn là bạn thực hiện giao thức cần thiết. Bạn có thể sử dụng cái này hay cái khác:
Cả hai giao thức đều giống nhau nhưng hãy xem xét như sau: Lý do để sử dụng scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...00:
Lý do để sử dụng scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...01:
Giao thức mặc định được sử dụng bởi lớp @route('/stepone') def auth_step_one(): callback = 'my absolute url to auth_step_two_callback' account = Account(credentials) url, state = account.con.get_authorization_url(requested_scopes=my_scopes, redirect_uri=callback) # the state must be saved somewhere as it will be needed later my_db.store_state(state) # example... return redirect(url) @route('/steptwo') def auth_step_two_callback(): account = Account(credentials) # retreive the state saved in auth_step_one my_saved_state = my_db.get_state() # example... # rebuild the redirect_uri used in auth_step_one callback = 'my absolute url to auth_step_two_callback' result = account.con.request_token(request.url, state=my_saved_state, redirect_uri=callback) # if result is True, then authentication was succesful # and the auth token is stored in the token backend if result: return render_template('auth_complete.html') # else ....8 là scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...00. Bạn có thể thực hiện các giao thức của riêng mình bằng cách kế thừa từ scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...06 để liên lạc với các API Microsoft khác. Bạn có thể khởi tạo và sử dụng các giao thức như thế này: scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...1 Resources:Mỗi điểm cuối API yêu cầu một tài nguyên. Điều này thường xác định chủ sở hữu của dữ liệu. Mỗi giao thức mặc định là tài nguyên 'tôi'. 'Me' là người dùng đã đồng ý, nhưng bạn có thể thay đổi hành vi này bằng cách cung cấp một tài nguyên mặc định khác cho hàm tạo giao thức.
Ví dụ: khi truy cập hộp thư được chia sẻ: scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...2 Điều này có thể được thực hiện tuy nhiên tại bất kỳ điểm nào. Ví dụ: ở cấp độ giao thức: scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...3 Thay vì xác định tài nguyên được sử dụng ở cấp độ tài khoản hoặc giao thức, bạn có thể cung cấp nó cho mỗi trường hợp sử dụng như sau: scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...4 Thông thường bạn sẽ làm việc với tài nguyên 'Me' mặc định, nhưng bạn cũng có thể sử dụng một trong những điều sau đây:
Bằng cách đặt tiền tố tài nguyên (chẳng hạn như 'người dùng:' hoặc 'nhóm:'), bạn giúp thư viện hiểu loại tài nguyên. Bạn cũng có thể vượt qua nó như 'người dùng/'. Tương tự áp dụng cho các tiền tố tài nguyên khác.'user:' or 'group:') you help the library understand the type of resource. You can also pass it like 'users/'. Same applies to the other resource prefixes. Lớp tài khoản và mô -đunThông thường bạn sẽ chỉ cần làm việc với lớp @route('/stepone') def auth_step_one(): callback = 'my absolute url to auth_step_two_callback' account = Account(credentials) url, state = account.con.get_authorization_url(requested_scopes=my_scopes, redirect_uri=callback) # the state must be saved somewhere as it will be needed later my_db.store_state(state) # example... return redirect(url) @route('/steptwo') def auth_step_two_callback(): account = Account(credentials) # retreive the state saved in auth_step_one my_saved_state = my_db.get_state() # example... # rebuild the redirect_uri used in auth_step_one callback = 'my absolute url to auth_step_two_callback' result = account.con.request_token(request.url, state=my_saved_state, redirect_uri=callback) # if result is True, then authentication was succesful # and the auth token is stored in the token backend if result: return render_template('auth_complete.html') # else ....8. Đây là một trình bao bọc xung quanh tất cả các chức năng. Nhưng bạn cũng chỉ có thể làm việc với các mảnh bạn muốn. Ví dụ: thay vì: scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...5 Bạn chỉ có thể làm việc với các phần cần thiết: scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...6 Nó cũng dễ dàng thực hiện một lớp tùy chỉnh. Chỉ cần kế thừa từ scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...08, xác định các điểm cuối và sử dụng kết nối để thực hiện các yêu cầu. Nếu cần cũng kế thừa từ giao thức để xử lý các khía cạnh kết hợp khác nhau với máy chủ API. scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...7 Hộp thưHộp thư nhóm chức năng của cả tin nhắn và thư mục email. Đây là những phạm vi cần thiết để làm việc với các lớp scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...09 và scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...10.
scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...8 Thư mục emailĐại diện cho một scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...11 trong hộp thư email của bạn. Bạn có thể nhận bất kỳ thư mục nào trong hộp thư của mình bằng cách yêu cầu các thư mục con hoặc lọc theo tên. scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...9 Thông điệpMột đối tượng email với tất cả dữ liệu và phương pháp. Tạo một thông điệp dự thảo dễ dàng như thế này: from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph # the default authentication method will be "on behalf of a user" account = Account(credentials) if account.authenticate(scopes=['basic', 'message_all']): print('Authenticated!') # 'basic' adds: 'offline_access' and 'https://graph.microsoft.com/User.Read' # 'message_all' adds: 'https://graph.microsoft.com/Mail.ReadWrite' and 'https://graph.microsoft.com/Mail.Send'0 Làm việc với các email đã lưu cũng dễ dàng: from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph # the default authentication method will be "on behalf of a user" account = Account(credentials) if account.authenticate(scopes=['basic', 'message_all']): print('Authenticated!') # 'basic' adds: 'offline_access' and 'https://graph.microsoft.com/User.Read' # 'message_all' adds: 'https://graph.microsoft.com/Mail.ReadWrite' and 'https://graph.microsoft.com/Mail.Send'1 Gửi hình ảnh nội tuyếnBạn có thể gửi hình ảnh nội tuyến bằng cách làm điều này: from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph # the default authentication method will be "on behalf of a user" account = Account(credentials) if account.authenticate(scopes=['basic', 'message_all']): print('Authenticated!') # 'basic' adds: 'offline_access' and 'https://graph.microsoft.com/User.Read' # 'message_all' adds: 'https://graph.microsoft.com/Mail.ReadWrite' and 'https://graph.microsoft.com/Mail.Send'2 Lấy các tiêu đề tin nhắnBạn có thể truy xuất các tiêu đề tin nhắn bằng cách làm điều này: from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph # the default authentication method will be "on behalf of a user" account = Account(credentials) if account.authenticate(scopes=['basic', 'message_all']): print('Authenticated!') # 'basic' adds: 'offline_access' and 'https://graph.microsoft.com/User.Read' # 'message_all' adds: 'https://graph.microsoft.com/Mail.ReadWrite' and 'https://graph.microsoft.com/Mail.Send'3 Lưu ý rằng chỉ các tiêu đề tin nhắn và các thuộc tính khác được thêm vào câu lệnh Chọn sẽ có mặt. Tiết kiệm như EMLTin nhắn và tin nhắn đính kèm có thể được lưu dưới dạng *.eml.
Sổ địa chỉNhóm địa chỉ Nhóm chức năng của cả thư mục liên hệ và liên hệ. Các nhóm phân phối Outlook không được hỗ trợ (bởi API của Microsoft). Đây là những phạm vi cần thiết để làm việc với các lớp scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...12 và scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...13.
Liên hệ với các thư mụcĐại diện cho một thư mục trong phần Liên hệ của bạn trong Office 365. Lớp địa chỉ đại diện cho thư mục chính (đó là một thư mục). Bạn có thể nhận bất kỳ thư mục nào trong sổ địa chỉ của mình bằng cách yêu cầu các thư mục con hoặc lọc theo tên. from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph # the default authentication method will be "on behalf of a user" account = Account(credentials) if account.authenticate(scopes=['basic', 'message_all']): print('Authenticated!') # 'basic' adds: 'offline_access' and 'https://graph.microsoft.com/User.Read' # 'message_all' adds: 'https://graph.microsoft.com/Mail.ReadWrite' and 'https://graph.microsoft.com/Mail.Send'6 Danh sách địa chỉ toàn cầuAPI Office 365 (cũng không phải API biểu đồ MS) không có khái niệm như danh sách địa chỉ toàn cầu Outlook. Tuy nhiên, bạn có thể sử dụng API người dùng để truy cập tất cả người dùng trong tổ chức của bạn. Không có sự đồng ý của quản trị viên, bạn chỉ có thể truy cập một vài thuộc tính của mỗi người dùng như tên và email và litte nhiều hơn. Bạn có thể tìm kiếm theo tên hoặc truy xuất một liên hệ chỉ định email hoàn chỉnh.
Để tìm kiếm danh sách địa chỉ toàn cầu (API người dùng): from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph # the default authentication method will be "on behalf of a user" account = Account(credentials) if account.authenticate(scopes=['basic', 'message_all']): print('Authenticated!') # 'basic' adds: 'offline_access' and 'https://graph.microsoft.com/User.Read' # 'message_all' adds: 'https://graph.microsoft.com/Mail.ReadWrite' and 'https://graph.microsoft.com/Mail.Send'7 Để lấy liên hệ qua email của họ: from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph # the default authentication method will be "on behalf of a user" account = Account(credentials) if account.authenticate(scopes=['basic', 'message_all']): print('Authenticated!') # 'basic' adds: 'offline_access' and 'https://graph.microsoft.com/User.Read' # 'message_all' adds: 'https://graph.microsoft.com/Mail.ReadWrite' and 'https://graph.microsoft.com/Mail.Send'8 Liên lạcMọi thứ được trả lại từ một ví dụ scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...12 là một ví dụ scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...13. Danh bạ có tất cả các thông tin được lưu trữ dưới dạng thuộc tính Tạo liên hệ từ scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...12: from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph # the default authentication method will be "on behalf of a user" account = Account(credentials) if account.authenticate(scopes=['basic', 'message_all']): print('Authenticated!') # 'basic' adds: 'offline_access' and 'https://graph.microsoft.com/User.Read' # 'message_all' adds: 'https://graph.microsoft.com/Mail.ReadWrite' and 'https://graph.microsoft.com/Mail.Send'9 Thư mục và người dùngĐối tượng thư mục có thể truy xuất người dùng. Một thể hiện người dùng chứa mặc định các thuộc tính cơ bản của người dùng. Nếu bạn muốn bao gồm nhiều hơn, bạn sẽ phải chọn các thuộc tính mong muốn theo cách thủ công. Kiểm tra danh sách địa chỉ toàn cầu để biết thêm thông tin. from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph account = Account(credentials, auth_flow_type='credentials', tenant_id='my-tenant-id') if account.authenticate(): print('Authenticated!')0 LịchChức năng lịch và sự kiện là nhóm trong một đối tượng scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...17. Một ví dụ scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...17 có thể liệt kê và tạo lịch. Nó cũng có thể liệt kê hoặc tạo các sự kiện trên lịch người dùng mặc định. Để sử dụng các lịch khác, hãy sử dụng ví dụ scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...19. Đây là những phạm vi cần thiết để làm việc với các lớp scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...17, scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...19 và scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...22.
Làm việc với ví dụ scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...17: from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph account = Account(credentials, auth_flow_type='credentials', tenant_id='my-tenant-id') if account.authenticate(): print('Authenticated!')1 Làm việc với các trường hợp scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...19: from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph account = Account(credentials, auth_flow_type='credentials', tenant_id='my-tenant-id') if account.authenticate(): print('Authenticated!')2 Ghi chú về lịch và sự kiện:
Nhiệm vụChức năng tác vụ được nhóm trong một đối tượng scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...27. Lưu ý rằng chức năng tác vụ hiện chỉ hoạt động với giao thức scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...01. Một ví dụ scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...27 có thể liệt kê và tạo các thư mục nhiệm vụ. Nó cũng có thể liệt kê hoặc tạo các tác vụ trên thư mục người dùng mặc định. Để sử dụng các thư mục khác, sử dụng thể hiện scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...11. Đây là những phạm vi cần thiết để làm việc với các lớp scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...27, scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...11 và scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...33.
Lịch.ReadWrite.shared from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph account = Account(credentials, auth_flow_type='credentials', tenant_id='my-tenant-id') if account.authenticate(): print('Authenticated!')3 lịch_shared_all from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph account = Account(credentials, auth_flow_type='credentials', tenant_id='my-tenant-id') if account.authenticate(): print('Authenticated!')4 Để đọc và lưu lịch từ hộp thư người dùng / người dùng khácLàm việc với ví dụ scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...17: Làm việc với các trường hợp scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...19: Ghi chú về lịch và sự kiện: Điều quan trọng là phải biết rằng khi truy vấn các sự kiện với scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...25 (là mặc định), bạn phải cung cấp một tham số truy vấn với các thuộc tính bắt đầu và kết thúc được xác định. Không giống như khi sử dụng scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...26, các thuộc tính này sẽ không lọc dữ liệu dựa trên các hoạt động bạn đặt trên truy vấn (Greater_equal, ít hơn, v.v.) nhưng chỉ cần lọc các sự kiện bắt đầu dữ liệu giữa các dữ liệu bắt đầu và kết thúc được cung cấp.
from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph account = Account(credentials, auth_flow_type='credentials', tenant_id='my-tenant-id') if account.authenticate(): print('Authenticated!')5 lịch_shared_all Khi sao chép DriveItem, API có thể trả về một bản sao trực tiếp của mục hoặc con trỏ vào tài nguyên sẽ thông báo về tiến trình của hoạt động sao chép. from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph account = Account(credentials, auth_flow_type='credentials', tenant_id='my-tenant-id') if account.authenticate(): print('Authenticated!')6 Bạn cũng có thể làm việc với quyền chia sẻ: from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph account = Account(credentials, auth_flow_type='credentials', tenant_id='my-tenant-id') if account.authenticate(): print('Authenticated!')7 Bạn cũng có thể: from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph account = Account(credentials, auth_flow_type='credentials', tenant_id='my-tenant-id') if account.authenticate(): print('Authenticated!')8 ExcelBạn có thể tương tác với các tệp Excel mới (.xlsx) được lưu trữ trong OneDrive hoặc thư viện tài liệu SharePoint. Bạn có thể truy xuất sổ làm việc, bảng tính, bảng và thậm chí dữ liệu di động. Bạn cũng có thể viết thư cho bất kỳ Excel trực tuyến. Để làm việc với các tệp Excel, trước tiên bạn phải truy xuất một thể hiện scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...45 bằng cách sử dụng chức năng OneDrive hoặc SharePoint. Các phạm vi cần thiết để làm việc với các lớp liên quan đến scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...46 và Excel giống nhau được sử dụng bởi OneDrive. Đây là cách bạn cập nhật giá trị ô: from O365 import Account credentials = ('my_client_id', 'my_client_secret') # the default protocol will be Microsoft Graph account = Account(credentials, auth_flow_type='credentials', tenant_id='my-tenant-id') if account.authenticate(): print('Authenticated!')9 Phiên làm bài tậpKhi tương tác với Excel, bạn có thể sử dụng phiên làm việc để thực hiện các thay đổi một cách hiệu quả theo cách liên tục hoặc không liên tục. Phiên này trở nên hữu ích nếu bạn thực hiện nhiều thay đổi đối với tệp Excel. Mặc định là sử dụng một phiên một cách liên tục. Phiên hết hạn sau một thời gian không hoạt động. Khi làm việc với các phiên liên tục, các phiên mới sẽ tự động được tạo khi các phiên cũ hết hạn. Tuy nhiên, bạn có thể thay đổi điều này khi tạo phiên bản scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...47: account = Account(credentials) account.authenticate(scopes=['basic', 'message_all'])0 Các đối tượng có sẵnSau khi tạo phiên bản scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...46, bạn sẽ có quyền truy cập vào các đối tượng sau:
Vài ví dụ: Đặt định dạng cho một phạm vi đã cho account = Account(credentials) account.authenticate(scopes=['basic', 'message_all'])1 Các cột tự động: account = Account(credentials) account.authenticate(scopes=['basic', 'message_all'])2 Nhận các giá trị từ bảng: account = Account(credentials) account.authenticate(scopes=['basic', 'message_all'])3 Điểm chia sẻAPI SharePoint được thực hiện nhưng chưa có tài liệu nào. Nhìn vào tệp SharePoint.py để có được thông tin chi tiết. Đây là những phạm vi cần thiết để làm việc với các lớp scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...49 và scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...50.
Người lập kế hoạchAPI kế hoạch được thực hiện nhưng chưa có tài liệu nào. Nhìn vào tệp Planner.py để có được thông tin chi tiết. Chức năng kế hoạch yêu cầu sự cho phép của quản trị viên. Danh mục triển vọngBạn có thể rút lại, cập nhật, tạo và xóa các danh mục Outlook. Các danh mục này có thể được sử dụng để phân loại tin nhắn, sự kiện và danh bạ. Đây là những phạm vi cần thiết để làm việc với các lớp scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...49 và scopes = ['my_required_scopes'] # you can use scope helpers here (see Permissions and Scopes section) account = Account(credentials) if not account.is_authenticated: # will check if there is a token and has not expired # ask for a login # console based authentication See Authentication for other flows account.authenticate(scopes=scopes) # now we are autheticated # use the library from now on # ...50.
Example: account = Account(credentials) account.authenticate(scopes=['basic', 'message_all'])4 Người lập kế hoạchAPI kế hoạch được thực hiện nhưng chưa có tài liệu nào. Nhìn vào tệp Planner.py để có được thông tin chi tiết.Chức năng kế hoạch yêu cầu sự cho phép của quản trị viên. Danh mục triển vọng Bạn có thể rút lại, cập nhật, tạo và xóa các danh mục Outlook. Các danh mục này có thể được sử dụng để phân loại tin nhắn, sự kiện và danh bạ. account = Account(credentials) account.authenticate(scopes=['basic', 'message_all'])5 MailboxSinstall.read Bạn có thể rút lại, cập nhật, tạo và xóa các danh mục Outlook. Các danh mục này có thể được sử dụng để phân loại tin nhắn, sự kiện và danh bạ. account = Account(credentials) account.authenticate(scopes=['basic', 'message_all'])6 MailboxSinstall.read- Chỉ đọc Cài đặt Outlook Bạn có thể rút lại, cập nhật, tạo và xóa các danh mục Outlook. Các danh mục này có thể được sử dụng để phân loại tin nhắn, sự kiện và danh bạ. account = Account(credentials) account.authenticate(scopes=['basic', 'message_all'])7 MailboxSinstall.read account = Account(credentials) account.authenticate(scopes=['basic', 'message_all'])8 -
account = Account(credentials) account.authenticate(scopes=['basic', 'message_all'])9 Cài đặt_allĐể đọc và viết cài đặt Outlook Sử dụng |