对Microsoft Graph进行API调用时请求400错误

dpa*_*ark 2 scribe microsoft-graph

我从Microsoft Graph API收到的错误是

error = {
  "code": "BadRequest",
  "innerError": {
    "date": "2017-04-10T19:37:08",
    "request-id": "973641dd-b150-4406-9f3b-fbcf6f7e5aa1"
  },
  "message": "The MIME type 'text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2' requires a '/' character between type and subtype, such as 'text/plain'."
}
Run Code Online (Sandbox Code Playgroud)

使用POSTman时,我可以从端点https://graph.microsoft.com/v1.0/me/contacts成功获取信息,但是转到scribe-java库OAuthRequest时,我收到此错误。
我的请求将转到带有2个标题的URL https://graph.microsoft.com/v1.0/me/contacts。授权->承载[令牌]
内容类型-> application / json

Nic*_*ick 7

尝试在您的请求中显式设置“ Accept”标头。POSTman可能默认将您设置为[Accept = text / html,image / gif,image / jpeg,*; q = .2,/ ; q = .2]

  • 伙计,你是天才,我花了 3 个小时来处理这个问题,但从未想过“接受”。谢谢你。 (2认同)

小智 5

您好,当我尝试使用图形 api 在 AzureAD 上创建新用户时,我遇到了同样的错误。我解决了我的问题,我将接受标头更改为“Accept”:“text/html,application/json”。供你参考


dpa*_*ark 0

事实证明 scribe-java 库没有正确设置请求。切换到 apache HttpClient 和 HttpGet 解决了我的问题。