【问题标题】:Authenticating for MS OneDrive对 MS OneDrive 进行身份验证
【发布时间】:2021-07-27 03:05:46
【问题描述】:

我正在开发一个 Spring-MVC 应用程序,我想在其中集成 OneDrive 功能。不幸的是,我找不到一些可用于 web 应用程序的 SDK。 Maven 存储库中的某些内容会有所帮助。谁能告诉我如何对 OneDrive 进行身份验证和使用一些库。

是不是有什么SDK可以直接放到POM.xml里面,像Google,dropbox等很多服务都有的。

以下是我尝试过的一些链接:

  1. https://msdn.microsoft.com/en-us/library/hh826531.aspx

  2. http://www.tjeerd.net/2014/08/23/onedrive-api-restful-programming-in-java/

  3. https://dev.onedrive.com/sample-code.htm

上面的示例是针对 android 的,没有涉及 webapp。谢谢。

【问题讨论】:

    标签: java onedrive


    【解决方案1】:

    将近五年后,我想补充一点,有一个适用于 MS Graph 的 Java SDK,它也将涵盖您的 OneDrive 访问权限:https://github.com/microsoftgraph/msgraph-sdk-java

    您可能已经解决了您的问题,但仅供参考。将此添加到您的 POM:

    <dependency>
      <groupId>com.microsoft.graph</groupId>
      <artifactId>microsoft-graph</artifactId>
      <version>2.7.1</version>
    </dependency>
    

    例如,您可以像这样在 OneDrive 中获取所有文件:

    Builder2 clientBuilder = GraphServiceClient.builder()
        .authenticationProvider(_accessTokenAuthProvider);
    
    IHttpProvider httpProvider = DefaultClientConfig
        .createWithAuthenticationProvider(_accessTokenAuthProvider)
        .getHttpProvider(createOkHttpClientBuilder().build());
    clientBuilder.httpProvider(httpProvider);
    
    IGraphServiceClient graphServiceClient = clientBuilder.buildClient();
    IDriveItemCollectionPage collectionPage = graphServiceClient.me().drive().root().children().buildRequest()
            .select("Id,Name,Folder,Size").get();
    

    在上面的代码 sn-p 中,您需要添加将实现IAuthenticationProvider, ICoreAuthenticationProvider 的 AuthenticationProvider。执行时,您将获得collectionPage,其中包含DriveItems 的列表。

    希望这对其他人有所帮助。

    【讨论】:

    • 非常感谢。无法验证,甚至不要在同一个项目上工作。 :-P
    【解决方案2】:

    我认为 Microsoft 没有用于 Web 应用程序的 OneDrive SDK。但是,您可以轻松地使用他们的 Rest API 来完成所有工作。 Rest API 非常简单。 https://dev.onedrive.com/README.htm

    他们也有控制台来试用这些 api https://apigee.com/OneDrive/embed/console/OneDrive

    【讨论】:

    • 您知道有关身份验证和那些 REST 调用的任何示例吗?
    • 您需要通过此链接dev.onedrive.com/auth/msa_oauth.htm 中描述的流程之一获取身份验证令牌。获得身份验证或刷新令牌后,您需要获得访问令牌(在同一链接中也提供了这些步骤)。获得访问令牌后,您可以使用 access_token 作为查询参数调用他们的其余 API。
    猜你喜欢
    • 1970-01-01
    • 2017-11-27
    • 1970-01-01
    • 2019-01-01
    • 1970-01-01
    • 2014-05-25
    • 1970-01-01
    • 1970-01-01
    • 2014-08-15
    相关资源
    最近更新 更多