Làm cách nào để gửi email từ office 365 bằng python?
Trong bài viết Tải dữ liệu danh sách SharePoint của Microsoft 365 bằng Python, tôi đã cung cấp các bước chi tiết để tải dữ liệu Danh sách SharePoint thông qua gói msal. Để biết chi tiết về cách cài đặt các gói Python cần thiết cũng như cách thiết lập , hãy tham khảo bài viết về SharePoint. Show
quyền thiết lậpChúng tôi cần thêm quyền để gửi email. Thư. Gửi. Quyền này cho phép bạn gửi email với tư cách là bất kỳ người dùng nào Sau khi thêm quyền, hãy đảm bảo bạn cũng cung cấp sự đồng ý cho ứng dụng Tạo kịch bản để gửi emailVới mã thông báo người dùng và người dùng đã sẵn sàng, giờ đây chúng tôi có thể sử dụng chúng để gửi email trong ứng dụng khách Python Thêm tập lệnh python với nội dung sau import json import msal import requests client_id = '***' client_secret = '***' tenant_id = '***' authority = f"https://login.microsoftonline.com/{tenant_id}" app = msal.ConfidentialClientApplication( client_id=client_id, client_credential=client_secret, authority=authority) scopes = ["https://graph.microsoft.com/.default"] result = None result = app.acquire_token_silent(scopes, account=None) if not result: print( "No suitable token exists in cache. Let's get a new one from Azure Active Directory.") result = app.acquire_token_for_client(scopes=scopes) # if "access_token" in result: # print("Access token is " + result["access_token"]) if "access_token" in result: userId = "***" endpoint = f'https://graph.microsoft.com/v1.0/users/{userId}/sendMail' toUserEmail = "***" email_msg = {'Message': {'Subject': "Test Sending Email from Python", 'Body': {'ContentType': 'Text', 'Content': "This is a test email."}, 'ToRecipients': [{'EmailAddress': {'Address': toUserEmail}}] }, 'SaveToSentItems': 'true'} r = requests.post(endpoint, headers={'Authorization': 'Bearer ' + result['access_token']}, json=email_msg) if r.ok: print('Sent email successfully') else: print(r.json()) else: print(result.get("error")) print(result.get("error_description")) print(result.get("correlation_id")) Hãy nhớ thay thế các biến được đánh dấu cho phù hợp. Đối với ID người dùng của tài khoản email, bạn có thể tìm thấy nó trong Azure Active Directory hoặc trung tâm quản trị Microsoft 365 Ngoài Microsoft Excel và PowerPoint, một công cụ văn phòng được sử dụng phổ biến khác là Outlook. Tôi nghĩ những người có kinh nghiệm làm việc sẽ quen thuộc với phần mềm Outlook. Nó được sử dụng để nhận và gửi email để liên lạc 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 trở nên dễ dàng theo cách Pythonic. Truy cập vào Email, Lịch, Danh bạ, OneDrive, v.v. Dễ thực hiện theo cách dễ dàng và dễ hiểu đối với người mới bắt đầu và cảm thấy phù hợp với lập trình viên python dày dạn kinh nghiệm Dự án hiện đang được phát triển và duy trì bởi Janscas Nhà phát triển cốt lõi
Chúng tôi luôn mở 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ề gửi tin nhắnfrom O365 import Account credentials = ('client_id', 'client_secret') account = Account(credentials) m = account.new_message() m.to.add('[email protected]') 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 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ì sau đây là một loại wiki Mục lục
Cài đặtO365 có sẵn trên pypi. tổ chức. Đơn giản chỉ cần chạy @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 ....5 để cài đặt nó Yêu cầu. >= Trăn 3. 4 Phụ thuộc dự án được cài đặt bởi pip
Cách sử dụngBước đầu tiên để có thể làm việc với thư viện này là đăng ký ứng dụng và truy xuất mã thông báo xác thực. Xem Xác thực Bạn nên thêm quyền "offline_access" và yêu cầu phạm vi này khi xác thực. Nếu không, thư viện sẽ chỉ có quyền truy cập vào tài nguyên người dùng trong 1 giờ. Xem Quyền và Phạm vi Với mã thông báo truy cập được truy xuất và lưu trữ, bạn sẽ có thể thực hiện các cuộc gọi api đến dịch vụ Mẫu phổ biến để kiểm tra xác thực và sử dụng thư viện là mẫu này ________số 8 xác thựcBạn chỉ có thể xác thực bằng cách sử dụng oauth athentication vì Microsoft đã ngừng sử dụng basic auth vào ngày 1 tháng 11 năm 2018 Hiện tại có ba phương pháp xác thực
Khi nào nên sử dụng cái này hay cái kia và các yêu cầu Chủ đềThay mặt người dùng (auth_flow_type=='ủy quyền')Thay mặt người dùng (công khai) (auth_flow_type=='công khai')Với danh tính của riêng bạn (auth_flow_type=='credentials')Đăng ký Ứng dụngBắt buộcYêu cầuYêu cầuChỉ cần có sự đồng ý của quản trị viên trên một số quyền nâng caoChỉ*O365 sẽ tự động làm mới mã thông báo cho bạn trên một trong hai 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, miễn là 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 đồ thị của Microsoft, gần như tương tự áp dụng cho API REST của Office 365 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. Nội dung sau áp dụng cho phương thức xác thực "thay mặt người dùng" vì đây là quy trình 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ần 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 viQuyềnKhi sử dụng oauth, bạn tạo một ứng dụng và cho phép người dùng truy cập và sử dụng một số tài nguyên. 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 người dùng) hoặc quyền ứng dụng. Cái trước được sử dụng khi phương thức xác thực là "thay mặt 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 người dùng"
Sau đó, người dùng của thư viện này 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. Đọc thư. Đọc Viết và Thư. Gửi quyền, nhưng ứng dụng chỉ có thể yêu cầu quyền truy cập vào Thư. Đọc Viết và Thư. gửi giấy phép. Điều này được thực hiện bằng cách cung cấp phạm vi cho đối tượ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 ....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 @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 ....4 Phạm vi triển khai 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ỏ giúp nhóm chức năng phạm vi và trừu tượng hóa giao thức được sử dụng Phạm vi HelperBao gồm phạm vi cơ bản'offline_access' và 'Người dùng. Đọc'hộp thư'Mail. Đọc'mailbox_shared'Mail. Đọc. Shared'message_send'Mail. Send'message_send_shared'Mail. Gửi. Shared'message_all'Mail. ReadWrite' và 'Thư. Gửi'message_all_shared'Mail. Đọc viết. Được chia sẻ' và 'Thư. Gửi. Shared'address_book'Danh bạ. Read'address_book_shared'Danh bạ. Đọc. Đã chia sẻ'address_book_all'Danh bạ. ReadWrite'address_book_all_shared'Danh bạ. Đọc viết. Shared'calendar'Calendars. Read'calendar_shared'Calendars. Đọc. Shared'calendar_all'Calendars. ReadWrite'calendar_shared_all'Calendars. Đọc viết. Nhiệm vụ được chia sẻ. Read'tasks_all'Tasks. ReadWrite'users'User. Đọc cơ bản. All'onedrive'Files. Đọc. All'onedrive_all'Files. Đọc viết. Tất cả các trang web'sharepoint'. Đọc. Tất cả'sharepoint_dl'Sites. Đọc viết. Tất cả các'Bạn có thể nhận được các phạm vi giống như trước khi sử dụng các giao thức và trình trợ giúp phạm vi như thế này @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 @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 ....5
Lưu trữ mã thông báoKhi 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 vị trí và cách lưu trữ mã thông báo bằng cách sử dụng Phần cuối mã thông báo thích hợp Bảo trọng. 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 Các phương thức 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 TokenBackend được định cấu hình đúng cách Trên thực tế, chỉ có hai cách được triển khai (nhưng bạn có thể dễ dàng triển khai nhiều hơn như Cookie Backend, Redis Backend, v.v. )
Ví dụ: sử dụng phụ trợ mã thông báo FileSystem from O365 import Account credentials = ('client_id', 'client_secret') account = Account(credentials) m = account.new_message() m.to.add('[email protected]') m.subject = 'Testing!' m.body = "George Best quote: I've stopped drinking, but only while I'm asleep." m.send()9 Và bây giờ sử dụng cùng một ví dụ 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 Để triển khai TokenBackend mới
Phương pháp from O365 import Account credentials = ('client_id', 'client_secret') account = Account(credentials) m = account.new_message() m.to.add('[email protected]') m.subject = 'Testing!' m.body = "George Best quote: I've stopped drinking, but only while I'm asleep." m.send()98 dự định sẽ được triển khai cho các môi trường có nhiều phiên bản Kết nối đang chạy song song. Phương pháp này sẽ kiểm tra xem đã đến lúc làm mới mã thông báo hay chưa. Chương trình phụ trợ đã chọn có thể lưu trữ cờ ở đâu đó để trả lời câu hỏi này. Điều này có thể tránh tình trạng chạy đua giữa các trường hợp khác nhau đang cố gắng làm mới mã thông báo cùng một lúc, khi chỉ một trường hợp thực hiện việc làm mới. Phương thức sẽ trả về ba giá trị có thể
Theo mặc định, điều này luôn trả về True vì giả sử 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 liên lạc 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. Tuy nhiên, bạn có thể sử dụng nhiều API khác của Microsoft miễn là bạn triển khai giao thức cần thiết Bạn có thể sử dụng cái này hay cái kia
Cả hai giao thức đều giống nhau nhưng hãy xem xét những điều 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ể triển khai 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 để giao tiếp với các API khác của Microsoft 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 Tài nguyênMỗ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 đều mặc định là tài nguyên 'ME'. '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 trình tạo giao thức
Ví dụ: khi truy cập hộp thư dùng chung 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 tài nguyê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 các tài nguyên sau
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ể chuyển nó như 'users/example@exampl. com'. Áp dụng tương tự cho các tiền tố tài nguyên khác Loại 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 có thể chỉ làm việc với những phần 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 Cũng dễ dàng triển khai 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 điểm cuối và sử dụng kết nối để thực hiện 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 giao tiế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ả thư và thư mục email Đây là các 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 # ...10Phạm vi thôĐược bao gồm trong Trình trợ giúp phạm viMô tảMail. ReadmailboxĐể chỉ đọc hộp thư của tôiMail. Đọc. Sharedmailbox_sharedĐể chỉ đọc người dùng khác / hộp thư dùng chungMail. Sendmessage_send, message_allĐể chỉ gửi messageMail. Gửi. Sharedmessage_send_shared, message_all_sharedĐể chỉ gửi tin nhắn với tư cách người dùng khác / hộp thư chungMail. ReadWritemessage_allĐể đọc và lưu thư trong hộp thư của tôiMail. Đọc viết. Sharedmessage_all_sharedĐể đọc và lưu thư trong hộp thư chung/người dùng khá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 # ...8 thư mục thư điện tửĐạ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ể lấy 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 thức của nó Tạo một tin nhắn nháp dễ dàng như thế này @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 ....50 Làm việc với các email đã lưu cũng dễ 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 ....51 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 @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 ....52 Truy xuất tiêu đề thưBạn có thể truy xuất tiêu đề thư bằng cách thực hiện việc này @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 ....53 Lưu ý rằng chỉ các tiêu đề thư và các thuộc tính khác được thêm vào câu lệnh chọn mới có mặt Lưu dưới dạng EMLTin nhắn và tin nhắn đính kèm có thể được lưu dưới dạng *. eml
Sổ địa chỉSổ Địa chỉ nhóm chức năng của cả Thư mục Liên hệ và Danh bạ. Nhóm phân phối Outlook không được hỗ trợ (Bởi API của Microsoft) Đây là các 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 # ...13Phạm vi thô Bao gồm trong Trình trợ giúp phạm vi Mô tả Liên hệ. Đọc sổ địa chỉ Để chỉ đọc danh bạ cá nhân của tôi Danh bạ. Đọc. Sharedaddress_book_sharedĐể chỉ đọc danh bạ của người dùng khác / hộp thư chung Liên hệ. ReadWrite address book_allĐể đọc và lưu danh bạ cá nhân Danh bạ. Đọc viết. Sharedaddress_book_all_shared Để đọc và lưu danh bạ từ người dùng khác / hộp thư chung Người dùng. Đọc cơ bản. AllusersĐể chỉ đọc các thuộc tính cơ bản từ người dùng trong tổ chức của tôi (Người dùng. Đọc. Tất cả yêu cầu sự đồng ý của quản trị viên) Thư mục liên hệĐại diện cho một Thư mục trong Phần Danh bạ của bạn trong Office 365. Lớp Sổ địa chỉ đại diện cho thư mục mẹ (chính nó là một thư mục) Bạn có thể lấy 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 @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 ....56 Danh sách địa chỉ toàn cầuOffice 365 API (Hoặc MS Graph API) không có khái niệm như Danh sách địa chỉ toàn cầu của 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 mình Nếu không có sự đồng ý của quản trị viên, bạn chỉ có thể truy cập một số thuộc tính của mỗi người dùng, chẳng hạn như tên và email, v.v. Bạn có thể tìm kiếm theo tên hoặc truy xuất một liên hệ chỉ định email đầy đủ
Để tìm kiếm Danh sách địa chỉ toàn cầu (API người 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 ....57 Để truy xuất một liên hệ qua email của họ @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 ....58 Liên lạcMọi thứ được trả về từ 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 # ...12 là 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 # ...13. Danh bạ có tất cả thông tin được lưu trữ dưới dạng thuộc tính Tạo một liên hệ từ 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 # ...12 @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 ....59 Thư mục và người dùngĐối tượng Directory có thể truy xuất người dùng Theo mặc định, một phiên bản Người dùng chứa 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 @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 ....90 LịchChức năng lịch và sự kiện đượ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 # ...17 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 # ...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 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 # ...19 Đây là các 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 # ...22Phạm vi thô Bao gồm trong Trình trợ giúp phạm vi Mô tả Lịch. ReadcalendarĐể chỉ đọc lịch cá nhân của tôi. Đọc. Sharedcalendar_sharedĐể chỉ đọc lịch của người dùng khác / hộp thư dùng chung Lịch. ReadWritecalendar_allĐể đọc và lưu lịch cá nhân Lịch. Đọc viết. Sharedcalendar_shared_allĐể đọc và lưu lịch từ người dùng khác/hộp thư chung Làm việc với 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 # ...17 @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 ....91 Làm việc với các 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 # ...19 @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 ....92 Ghi chú về Lịch và Sự kiện
nhiệm vụChức năng nhiệm 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 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 # ...27 có thể liệt kê và tạo các thư mục tác 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, hãy sử dụng 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 # ...11 Đây là những phạm vi cần thiết để làm việc với các lớp ________ 827, ________ 811 và ________ 832 Phạm vi thô Bao gồm trong Trình trợ giúp phạm vi Mô tảTác vụ. Readt taskĐể chỉ đọc các nhiệm vụ cá nhân của tôiTasks. ReadWritetasks_allĐể đọc và lưu lịch cá nhânLàm việc với 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 # ...27 @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 ....93 Làm việc với các 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 # ...11 @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 ....94 Một ổ đĩaLớ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 # ...35 xử lý tất cả các chức năng xung quanh Bộ lưu trữ Thư viện Tài liệu và Ổ đĩa trong SharePoint 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 # ...35 cho phép truy xuất 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 # ...37 xử lý tất cả Tệp và Thư mục từ bên trong 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 # ...35 đã chọn. Thông thường bạn sẽ chỉ cần làm việc với ổ đĩa mặc định. Nhưng các 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 # ...35 có thể xử lý nhiều ổ đĩa 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 # ...37 sẽ cho phép bạn làm việc với Thư mục và Tệp Đây là những phạm vi cần thiết để làm việc với các lớp ________ 835, ________ 837 và ________ 843 Phạm vi thôĐược bao gồm trong Trình trợ giúp phạm viTệp mô tả. Đọc Để chỉ đọc tệp của tôi Tệp. Đọc. AllonedriveĐể chỉ đọc tất cả các tệp mà người dùng có quyền truy cậpFiles. Đọc Viết Để đọc và lưu tệp của tôi Tệp. Đọc viết. Allonedrive_allĐể đọc và lưu tất cả các tệp mà người dùng có quyền truy cậ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 ....95 Cả Tệp và Thư mục đều là DriveItems. Cả Hình ảnh và Ảnh đều là Tệp, nhưng Ảnh cũng là Hình ảnh. Tất cả đều có một số phương thức và thuộc tính khác nhau. Hãy cẩn thận khi sử dụng 'is_xxxx' Khi sao chép một DriveItem, api có thể trả về một bản sao trực tiếp của mục đó hoặc một con trỏ tới tài nguyên sẽ thông báo về tiến trình của thao tác sao ché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 ....96 Bạn cũng có thể làm việc với quyền chia sẻ @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 ....97 Bạn cũng có thể @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 ....98 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, trang tính, bảng và thậm chí cả dữ liệu ô. Bạn cũng có thể ghi vào 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 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 # ...44 bằ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 # ...45 và Excel giống nhau được sử dụng bởi OneDrive Đây là cách bạn cập nhật một giá trị ô @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 ....99 Phiên sổ làm việcKhi tương tác với excel, bạn có thể sử dụng phiên sổ 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 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 phiên liên tục, phiên mới sẽ tự động được tạo khi 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 # ...46 @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 ....40 đố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 # ...45, 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 nhất định @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 ....41 Cột tự động điều chỉnh @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 ....42 Nhận các giá trị từ Bả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 ....43 Điểm chia sẻSharePoint api đã xong nhưng chưa có tài liệu. Nhìn vào điểm chia sẻ. py để có thông tin chi tiết Đây là các 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 # ...48 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 # ...49Phạm vi thô Bao gồm trong Trình trợ giúp phạm vi Mô tả Trang web. Đọc. AllsharepointĐể chỉ đọc các trang web, danh sách và mụcTrang web. Đọc viết. Allsharepoint_dlĐể đọc và lưu các trang web, danh sách và mục Người lập kế hoạchApi planner đã hoàn thành nhưng chưa có tài liệu nào. Nhìn vào kế hoạch. py để có thông tin chi tiết Chức năng lập kế hoạch yêu cầu Quyền của quản trị viên Danh mục OutlookBạn có thể truy xuất, cập nhật, tạo và xóa các danh mục triển vọng. 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à các 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 # ...48 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 # ...49Phạm vi thôĐược bao gồm trong Trình trợ giúp phạm viMô tảMailboxSettings. Đọc-Để chỉ đọc cài đặt triển vọng MailboxSettings. ReadWritesettings_allĐể đọc và ghi cài đặt triển vọng Thí dụ @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 ....44 công dụngphân trangKhi sử dụng một số phương thức nhất định, có thể bạn yêu cầu nhiều mục hơn số lượng mà api có thể trả về trong một lệnh gọi api. Trong trường hợp này, Api, trả về url "liên kết tiếp theo" nơi bạn có thể lấy thêm dữ liệu Khi trường hợp này xảy ra, các phương thức trong thư viện này sẽ trả về 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 # ...52 trừu tượng hóa tất cả những điều này thành một trình vòng lặp duy nhất. Đối tượng phân trang sẽ yêu cầu "liên kết tiếp theo" ngay khi cần Ví dụ @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 ....45 Khi sử dụng một số phương pháp nhất định, bạn sẽ có tùy chọn chỉ định không chỉ tùy chọn giới hạn (số lượng mục được trả lại) mà còn tùy chọn hàng loạt. Tùy chọn này sẽ chỉ ra phương thức yêu cầu dữ liệu tới api theo lô cho đến khi đạt đến giới hạn hoặc dữ liệu được tiêu thụ. Điều này hữu ích khi bạn muốn tối ưu hóa bộ nhớ hoặc độ trễ của mạng Ví dụ @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 ....46 Trình trợ giúp truy vấnKhi sử dụng API Office 365, bạn có thể lọc, sắp xếp, chọn, mở rộng hoặc tìm kiếm trên một số trường. Quá trình lọc này tẻ nhạt như đang sử dụng Giao thức dữ liệu mở (OData) Mỗ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 # ...08 (chẳng hạn như 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) triển khai một phương thức new_query sẽ trả về một 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 # ...55. 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 # ...55 này có thể xử lý việc lọc, sắp xếp, chọn, mở rộng và tìm kiếm rất dễ dàng Ví dụ @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 ....47 Bạn cũng có thể chỉ định dữ liệu cụ thể sẽ được truy xuất bằng "chọ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 ....48 Bạn cũng có thể tìm kiếm nội dung. Như đã nói trong tài liệu đồ thị
@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 ....49 Yêu cầu xử lý lỗiBất cứ khi nào xảy ra lỗi Yêu cầu, đối tượng kết nối sẽ đưa ra một ngoại lệ. Sau đó, ngoại lệ sẽ được ghi lại và ghi vào thiết bị xuất chuẩn với thông báo của nó, trả về Sai (Không, Sai, [], v.v. ) HttpErrors 4xx (Yêu cầu không hợp lệ) và 5xx (Lỗi máy chủ nội bộ) được coi là ngoại lệ và cũng do kết nối gây ra. Bạn có thể yêu cầu @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 không tăng lỗi http bằng cách chuyể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 # ...58 (mặc định là True) Tôi có thể gửi email từ 365 không?Chọn Trang chủ > Email mới. Thêm người nhận, chủ đề và thư trong nội dung email. Chọn Gửi .
Bạn có thể gửi email bằng Python không?Python cung cấp ` thư viện để gửi email- “SMTP lib” . “smtplib” tạo đối tượng phiên máy khách Giao thức chuyển thư đơn giản được sử dụng để gửi email đến bất kỳ id email hợp lệ nào trên internet. |