Java Microsoft图形api作用域无效
我正在Java项目中使用MicrosoftGraph的Java库。我的代码如下:Java Microsoft图形api作用域无效,java,microsoft-graph-api,microsoft-graph-sdks,microsoft-graph-calendar,Java,Microsoft Graph Api,Microsoft Graph Sdks,Microsoft Graph Calendar,我正在Java项目中使用MicrosoftGraph的Java库。我的代码如下: String clientId = "my client id"; List<String> scopes = Arrays.asList("https://graph.microsoft.com/calendars.read"); String clientSecret = "my client secret"; String tenant = "my tenant i
String clientId = "my client id";
List<String> scopes = Arrays.asList("https://graph.microsoft.com/calendars.read");
String clientSecret = "my client secret";
String tenant = "my tenant id";
NationalCloud nationalCloud = NationalCloud.Global;
ClientCredentialProvider authProvider = new ClientCredentialProvider(
clientId,
scopes,
clientSecret,
tenant,
nationalCloud);
IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Calendar calendar = graphClient.me().calendar()
.buildRequest()
.get();
我安装了以下maven依赖项:
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>org.apache.oltu.oauth2.client</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>microsoft-graph-auth-jar</groupId>
<artifactId>microsoft-graph-auth-jar</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph</artifactId>
<version>1.5.0</version>
</dependency>
org.apache.oltu.oauth2
org.apache.oltu.oauth2.client
1.0.1
com.microsoft.graph
微软图形核心
1.0.0
microsoft图形验证jar
microsoft图形验证jar
0.1.0-SNAPSHOT
com.microsoft.graph
微软图形
1.5.0
我不得不手动下载MicrosoftGraphAuth的jar,并使用mvn install:install文件进行安装
为什么会出现“无效范围”错误
是因为“委托”权限吗?问题不是因为“委托”权限 您正在使用,此提供程序在登录url中设置
grant\u type=client\u凭据。它将只使用https://graph.microsoft.com/.default
作为其范围
您需要使用https://graph.microsoft.com/.default
了解解决问题的范围。它将授予您在应用程序中定义的权限。您好。当我使用.default作用域时,我得到错误:Bad Request:Current authenticated context对此请求无效。当向需要用户登录的端点发出请求时,会发生这种情况。例如,/me需要一个已登录的用户。代表用户获取令牌以向这些端点发出请求。对于移动和本机应用程序,使用OAuth 2.0授权代码流;对于单页web应用程序,使用OAuth 2.0隐式代码流。
那么,我应该如何获取日历?如果删除了“我”,你能显示代码吗?这是另一个问题。在客户端凭据流中,没有适用于我的上下文。您正在使用“我”,即Calendar Calendar=graphClient。Me()
Calendar()…请阅读此[文章](),这将帮助您解决问题。
<dependency>
<groupId>org.apache.oltu.oauth2</groupId>
<artifactId>org.apache.oltu.oauth2.client</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph-core</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>microsoft-graph-auth-jar</groupId>
<artifactId>microsoft-graph-auth-jar</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph</artifactId>
<version>1.5.0</version>
</dependency>