Python Adal - невозможно использовать токен доступа для получения сообщений Outlook

Это означает, что наиболее переносимым способом определения реализации методов классов шаблонов является определение их внутри определения класса шаблона.

template < typename ... >
class MyClass
{

    int myMethod()
    {
       // Not just declaration. Add method implementation here
    }
};
0
задан SoapyDonuts 3 March 2019 в 17:19
поделиться

2 ответа

Для всех, кто заинтересован, это код, который я использовал для решения моей проблемы с токеном доступа:

def save_windows_refreshtoken(app_name, client_id, client_secret):

#import adal
#import requests
import json
import pandas as pd


# OAuth endpoints given in Outlook API documentation
authorization_base_url = 'https://login.microsoftonline.com/common/oauth2/authorize'
token_url = 'https://login.microsoftonline.com/common/oauth2/token' #provides a refresh and access token

redirect_uri = "http://localhost:8000"

from requests_oauthlib import OAuth2Session
outlook = OAuth2Session(client_id,redirect_uri=redirect_uri)

# Redirect  the user owner to the OAuth provider (i.e. Outlook) using an URL with a few key OAuth parameters.
authorization_url, state = outlook.authorization_url(authorization_base_url)
print('Please go here and authorize,', authorization_url)

#The above redirects you to a localhost page (which is blank) but returns a string containing a code which can be used below
#rememebr the search for "&" because there's a couple of bits of data after the code that need to be deleted from the code string before it can be used

# Get the authorization verifier code from the callback url
redirect_response = input('Paste the full redirect URL here:')

# Fetch the access token
token = outlook.fetch_token(token_url,client_secret=client_secret,code=redirect_response)


#convert the returned token json into a dataframe
j_dump = json.dumps(token, sort_keys=True,indent=4, separators=(',', ': ')) #pull out the value data from the json file, messages are stored in value

df = pd.read_json(j_dump) #read the json file into a dataframe

first_row = df.iloc[0] #pull the first row so we can format a new table from it

d = {
    'app_name' : pd.Series([app_name]),
    'refresh_token' : pd.Series([first_row.refresh_token])
    }
data = pd.DataFrame(d)
0
ответ дан SoapyDonuts 3 March 2019 в 17:19
поделиться

Вы получаете сообщения с acqu_token_with_username_password () , потому что вы получаете токен для данного ресурса через учетные данные пользователя.

Поскольку поток учетных данных клиента используется для обратного канала (связь сервера с сервером), пользователь не участвует в этом, и вы получаете токен участника службы.

Я бы предложил использовать от имени потока или потока кода авторизации ( acqu_token_with_authorization_code ), чтобы получить токен для данного ресурса через код авторизации для серверного приложения и вызвать API outlook для чтения сообщений. [ 115]

Ниже приведена ссылка (Outlook Mail API и Python):

https://github.com/jasonjoh/python_tutorial/tree/outlook-api

Библиотека Python adal поддерживает другие методы аутентификации. Ниже приведена ссылка на документацию: https://adal-python.readthedocs.io/en/latest/

. Мы предлагаем такие службы Office 365, как OneNote, Outlook, Excel, OneDrive Microsoft Teams, Planner и SharePoint теперь доступны в Microsoft Graph.

https://docs.microsoft.com/en-us/previous-versions/office/office-365-api/

0
ответ дан MohitDhingra-MSFT 3 March 2019 в 17:19
поделиться
Другие вопросы по тегам:

Похожие вопросы: