如何使用python访问Azure广告组列表?

如何使用python访问Azure广告组列表?,python,azure,active-directory,Python,Azure,Active Directory,我是python新手。我发现以下示例代码用于从中检索Azure广告组 代码是: ########### Python 3.2 ############# import http.client, urllib.request, urllib.parse, urllib.error, base64 # OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us

我是python新手。我发现以下示例代码用于从中检索Azure广告组

代码是:

########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64

# OAuth2 is required to access this API. For more information visit: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks

headers = {}

params = urllib.parse.urlencode({
# Specify values for the following required parameters
'api-version': '1.5',
})

try:
    conn = http.client.HTTPSConnection('graph.windows.net')
    #Specify values for path parameters (shown as {...}) and request body if needed
    conn.request("GET", "/myorganization/groups?%s" % params, "", headers)
    response = conn.getresponse()
    data = response.read()
    print(data)
    conn.close()
except Exception as e:
    print("[Errno {0}] {1}".format(e.errno, e.strerror))

####################################
一切都很好,但我不知道“headers={}”的值是多少


我需要帮助我为此花了很多时间,但还没有成功。

根据我的理解,您需要将Oauth授权信息写入标题中,如下面的代码:

headers = {
    #set your access token
    'Authorization':'your access token'
}
在访问Graph API之前,您需要获取访问令牌表单AD。您可以将授权信息添加到头和请求中。 关于如何获取访问令牌,我建议您可以参考此页面:

Hi@Kapil已经知道如何从Azure active directory获取数据了吗?如果有人像我一样通过搜索找到了这个,你可能会想看看这个: