Azure图形API 403错误使用Java教程
我一直在通过一个文件: 但是,当我运行项目时,我会被重定向到ADFS登录页面,在身份验证之后,我收到了以下错误: java.io.IOException:服务器返回URL的HTTP响应代码:403: 我从本地主机运行时出现此错误。我还将示例应用程序部署到Azure,并得到了相同的错误 我已在active directory>应用程序注册>所需权限中向Graph API添加了读取目录权限。我还添加了Windows Azure Active Directory权限(登录并读取用户配置文件)Azure图形API 403错误使用Java教程,java,azure,graph,Java,Azure,Graph,我一直在通过一个文件: 但是,当我运行项目时,我会被重定向到ADFS登录页面,在身份验证之后,我收到了以下错误: java.io.IOException:服务器返回URL的HTTP响应代码:403: 我从本地主机运行时出现此错误。我还将示例应用程序部署到Azure,并得到了相同的错误 我已在active directory>应用程序注册>所需权限中向Graph API添加了读取目录权限。我还添加了Windows Azure Active Directory权限(登录并读取用户配置文件) 这是常
这是常见的错误吗?我是否使用了错误版本的Graph API?我试过其他问题的几种解决方案,但都不起作用 根据AAD Graph API的新官方文档参考,代码中的
API版本
属性似乎应更改为1.6
。请试一试
同时,还有一个列表,您可以找到AAD图形API调用的常见错误代码403
的描述。并检查您的问题是否属于以下错误之一:Authentication\u Unauthorized
,Authorization\u RequestDenied
&目录
任何更新,请随时通知我。Azure Graph API似乎需要URI连接类型,而不是java教程使用的HttpUrlConnection。这在没有403错误的情况下工作:
try{
// OAuth2 is required to access this API. For more information visit:
// https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
// Specify values for path parameters (shown as {...})
URIBuilder builder = new URIBuilder("https://graph.windows.net/swisherint.onmicrosoft.com/users");
// Specify values for the following required parameters
builder.setParameter("api-version", "1.6");
// Specify values for optional parameters, as needed
// builder.setParameter("$filter", "startswith(displayName,'A')");
URI uri = builder.build();
HttpGet request = new HttpGet(uri);
HttpResponse response = httpclient.execute(request);
HttpEntity entity = response.getEntity();
if (entity != null) {
System.out.println(EntityUtils.toString(entity));
}
users = EntityUtils.toString(entity);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
感谢您的回复
KB工作得很好!谢谢