简体   繁体   English

访问 Microsoft Graph API 的方法

[英]Ways to access Microsoft Graph API

I am trying to access Microsoft Graph API using the following code in Java :-我正在尝试使用以下 Java 代码访问 Microsoft Graph API:-

    String url_str = "https://graph.microsoft.com/v1.0/users/";
    String access_token = getAccessToken();
    url = new URL(url_str);
    con = ( HttpURLConnection )url.openConnection();
    con.setDoInput(true);
    con.setDoOutput(true);
    con.setUseCaches(false);
    con.setRequestMethod("GET");
    con.setRequestProperty("Authorization", access_token);
    con.setRequestProperty("Accept","application/json");
    con.connect();

    br = new BufferedReader(new InputStreamReader( con.getInputStream() ));
    String str = null;
    String line;
    while((line = br.readLine()) != null) {
        str += line;
    }
    System.out.println(str);
} catch (Exception e) {
    e.printStackTrace();
}

Currently I am getting JSON String which i will need to parse further.目前我正在获取 JSON 字符串,我需要进一步解析它。 All I want to know is there any other way which will reduce the pain of deserialization or something more better.我只想知道有没有其他方法可以减轻反序列化的痛苦或更好的方法。

Martin 回答的更新,Java SDK 已发布并可用于公共预览:- https://github.com/microsoftgraph/msgraph-sdk-java

Im not aware of any Java SDK for Microsoft Graph.我不知道有任何适用于 Microsoft Graph 的 Java SDK。 However, you can use jsonutil to generate your java objects which will reduce at least some work.但是,您可以使用jsonutil生成 Java 对象,这至少会减少一些工作。

Edit: As mentioned by Pranay , a Java SDK is released, you should use this instead.编辑:正如Pranay提到的,Java SDK 已发布,您应该改用它。

You should use the newly-released Java SDK for Microsoft Graph.您应该使用新发布的用于 Microsoft Graph 的 Java SDK。 More details were recently postedhere , and the github repo for the SDK is here .最近在此处发布更多详细信息,SDK 的 github 存储库在此处

Another Java client for Microsoft Graph is odata-client which has support for the Graph v1.0, Beta, Graph Explorer endpoints and for Dynamics CRM and Analytics for Devops OData services. Microsoft Graph 的另一个 Java 客户端是odata-client ,它支持 Graph v1.0、Beta、Graph Explorer 端点以及 Dynamics CRM 和 Analytics for Devops OData 服务。 I was an early collaborator on the msgraph-sdk-java library and the problems there led me to create what I think is a much stronger product.我是msgraph-sdk-java库的早期合作者,那里的问题促使我创建了我认为更强大的产品。 In particular odata-client-msgraph (and the sibling libraries)特别是odata-client-msgraph (和兄弟库)

  • uses immutability使用不变性
  • detects changes for patching检测补丁的变化
  • models inheritance模型继承
  • extensively uses fluent builders广泛使用流利的构建器
  • implements java.util.Stream on collections在集合上实现 java.util.Stream
  • provides easier authentication提供更简单的身份验证
  • offers better type safety提供更好的类型安全
  • has very clean generated code有非常干净的生成代码
  • has better discoverability具有更好的可发现性
  • has decent unit test coverage of API interactions具有良好的 API 交互单元测试覆盖率
  • offers email helpers for that part of the API为 API 的那部分提供电子邮件助手
  • is released very frequently in line with frequent service updates根据频繁的服务更新非常频繁地发布

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM