无法使用管理员凭据通过 Graph API 列出 Office 365 域中的用户。

huangapple go评论101阅读模式
英文:

Could not list the users in the Office 365 domain with administrator credentials using graph api

问题

我正在尝试列出 Office 365 域中的用户。我正在使用 Graph API。我在 Azure AD 中注册了我的应用程序,并获得了 Directory.Read 权限。我能够获取访问令牌,但是当我尝试发送列出用户的请求时,返回了一个错误:

 {"odata.error":{"code":"Request_DataContractVersionMissing","message":{"lang":"en",
  "value":"The specified api-version is invalid. The value must exactly match a supported 
   version."}}}

这是我发送的请求:

apiUrl := "https://graph.windows.net/"
resource := "vstoregrid.com/users"
data := url.Values{}
data.Set("api-version", "2013-04-05")
authbear := "Bearer "
authbear += accessobj.Access_token

u, _ := url.ParseRequestURI(apiUrl)
u.Path = resource
urlStr := fmt.Sprintf("%v", u)

client := &http.Client{}

r, _ := http.NewRequest("GET", urlStr, bytes.NewBufferString(data.Encode()))
r.Header.Add("Content-Type", "application/json")
r.Header.Set("Authorization", authbear)
r.Header.Add("Host", "graph.windows.net")
r.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))

我按照文档中指定的版本进行了设置。我错在哪里?

英文:

I am trying to list the users in an office 365 domain. I am using the graph API. I registered my application in azure AD with Directory.Read permissions. I am able to retrieve an access token, but when I try to send a request to list the users it returns an error:

 {"odata.error":{"code":"Request_DataContractVersionMissing","message":{"lang":"en",
  "value":"The specified api-version is invalid. The value must exactly match a supported 
   version."}}}

This is the request I make:

apiUrl := "https://graph.windows.net/"
	resource := "vstoregrid.com/users"
	data := url.Values{}
	data.Set("api-version", "2013-04-05")
	authbear := "Bearer "
	authbear += accessobj.Access_token

	u, _ := url.ParseRequestURI(apiUrl)
	u.Path = resource
	urlStr := fmt.Sprintf("%v", u)

	client := &http.Client{}

	r, _ := http.NewRequest("GET", urlStr, bytes.NewBufferString(data.Encode()))
	r.Header.Add("Content-Type", "application/json")
	r.Header.Set("Authorization", authbear)
	r.Header.Add("Host", "graph.windows.net")
	r.Header.Add("Content-Length", strconv.Itoa(len(data.Encode())))

I am using the version as specified in the documentation. Where am I going wrong?

答案1

得分: 1

根据结果中的错误信息所说:

> 指定的 API 版本无效。值必须与支持的版本完全匹配。

您指定的 API 版本为:

data.Set("api-version", "2014-04-05")

"2014-04-05" 不是一个有效的 API 版本。请参阅此处的支持版本列表

支持的版本有:

  • "1.5"
  • "2013-11-08"
  • "2013-04-05"

很可能您想使用的是 API 版本 "2013-04-05"

data.Set("api-version", "2013-04-05")
英文:

As the error message says in the result:

> The specified api-version is invalid. The value must exactly match a supported
version.

You specified api version:

data.Set("api-version", "2014-04-05")

"2014-04-05" is not a valid api version. See the list of supported versions here.

Supported versions:

  • "1.5"
  • "2013-11-08"
  • "2013-04-05"

Most likely you wanted to use the api version "2013-04-05":

data.Set("api-version", "2013-04-05")

huangapple
  • 本文由 发表于 2015年2月25日 18:05:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/28716112.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定