将事件发布到microsoft graph时获取错误(java.lang.NoSuchMethodError:okhttp3.Request$Builder.tag)
我正在尝试使用microsoft graph api实现get和post方法。 Java代码:将事件发布到microsoft graph时获取错误(java.lang.NoSuchMethodError:okhttp3.Request$Builder.tag),java,spring-boot,microsoft-graph-api,Java,Spring Boot,Microsoft Graph Api,我正在尝试使用microsoft graph api实现get和post方法。 Java代码: IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider(authProvider) .buildClient(); graphClient.me().calendar().events().buildRequest().post(ev
IGraphServiceClient graphClient =
GraphServiceClient.builder().authenticationProvider(authProvider)
.buildClient();
graphClient.me().calendar().events().buildRequest().post(event);
User user = graphClient.me().buildRequest().get();
点击api时,我会出现以下错误:
线程“main”java.lang.NoSuchMethodError中出现异常:okhttp3.Request$Builder.tag(Ljava/lang/Class;Ljava/lang/Object;)Lokhttp3/Request$Builder;
在com.microsoft.graph.http.CoreHttpProvider.getHttpRequest上(CoreHttpProvider.java:257)
位于com.microsoft.graph.http.CoreHttpProvider.sendRequestInternal(CoreHttpProvider.java:397)
位于com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:220)
位于com.microsoft.graph.http.CoreHttpProvider.send(CoreHttpProvider.java:200)
位于com.microsoft.graph.http.BaseRequest.send(BaseRequest.java:345)
位于com.microsoft.graph.requests.extensions.EventRequest.post(EventRequest.java:135)
在com.microsoft.graph.requests.extensions.EventCollectionRequest.post(EventCollectionRequest.java:75)上
graph和graph auth api的Maven版本为:
<!-- https://mvnrepository.com/artifact/com.microsoft.graph/microsoft-graph -->
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph</artifactId>
<version>2.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.microsoft.graph/microsoft-graph-auth -->
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph-auth</artifactId>
<version>0.3.0-SNAPSHOT</version>
</dependency>
com.microsoft.graph
微软图形
2.5.0
com.microsoft.graph
microsoft图形验证
0.3.0-快照
请帮我解决这个问题
这是主要的方法:
public static void main(String[] args) {
UsernamePasswordProvider authProvider = new UsernamePasswordProvider("{client_id}",
Arrays.asList("https://graph.microsoft.com/.default"),
"{username}", "{password}", NationalCloud.Global,
"{tenant_id}", "{client_secret}");
IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider(authProvider)
.buildClient();
Event event = new Event();
event.subject = "Let's go for lunch";
ItemBody body = new ItemBody();
body.contentType = BodyType.HTML;
body.content = "Does mid month work for you?";
event.body = body;
DateTimeTimeZone start = new DateTimeTimeZone();
start.dateTime = "2021-01-15T12:00:00";
start.timeZone = "Pacific Standard Time";
event.start = start;
DateTimeTimeZone end = new DateTimeTimeZone();
end.dateTime = "2021-01-15T14:00:00";
end.timeZone = "Pacific Standard Time";
event.end = end;
Location location = new Location();
location.displayName = "";
event.location = location;
LinkedList<Attendee> attendeesList = new LinkedList<Attendee>();
Attendee attendees = new Attendee();
EmailAddress emailAddress = new EmailAddress();
emailAddress.address = "abc@gmail.com";
emailAddress.name = "Abcd";
attendees.emailAddress = emailAddress;
attendees.type = AttendeeType.REQUIRED;
attendeesList.add(attendees);
event.attendees = attendeesList;
graphClient.me().calendar().events().buildRequest().post(event);
log.info("created the event");
}
publicstaticvoidmain(字符串[]args){
UsernamePasswordProvider authProvider=新的UsernamePasswordProvider(“{client\u id}”),
Arrays.asList(“https://graph.microsoft.com/.default"),
“{username}”,“{password}”,NationalCloud.Global,
“{tenant_id},{client_secret}”);
IGraphServiceClient graphClient=GraphServiceClient.builder().authenticationProvider(authProvider)
.buildClient();
事件=新事件();
event.subject=“我们去吃午饭吧”;
ItemBody=新的ItemBody();
body.contentType=BodyType.HTML;
body.content=“月中对您有用吗?”;
event.body=body;
DateTimeZone start=新的DateTimeZone();
start.dateTime=“2021-01-15T12:00:00”;
start.timeZone=“太平洋标准时间”;
event.start=开始;
DateTimeZone end=新的DateTimeZone();
end.dateTime=“2021-01-15T14:00:00”;
end.timeZone=“太平洋标准时间”;
event.end=结束;
位置=新位置();
location.displayName=“”;
event.location=位置;
LinkedList AttendesList=新建LinkedList();
与会者=新与会者();
EmailAddress EmailAddress=新的EmailAddress();
emailAddress.address=”abc@gmail.com";
emailAddress.name=“Abcd”;
Attendes.emailAddress=电子邮件地址;
Attendes.type=AttendeType.REQUIRED;
AttendesList.add(与会者);
event.attendes=与会者列表;
graphClient.me().calendar().events().buildRequest().post(事件);
log.info(“创建事件”);
}
看到异常(NoSuchMethodError),您找到了类,因此在类路径中有一个okhttp。我的猜测是,使用了旧版本的okhttp(可能是因为其他依赖关系),因此出现了依赖关系冲突
当java代码试图调用一个类上不存在的方法时,会出现java.lang.NoSucMethodError,该方法可以是静态的,也可以是非静态的
先生,请添加此依赖项并重试
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.9</version>
</dependency>
com.squareup.okhttp3
okhttp
3.14.9
如果应用程序存在依赖项冲突,则将其添加到
要解决这些问题,请执行以下操作:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.9</version>
</dependency>
</dependencies>
</dependencyManagement>
com.squareup.okhttp3
okhttp
3.14.9
看到异常(NoSuchMethodError),您找到了类,因此在类路径中有一个okhttp。我的猜测是,使用了旧版本的okhttp(可能是因为其他依赖关系),因此出现了依赖关系冲突
当java代码试图调用一个类上不存在的方法时,会出现java.lang.NoSucMethodError,该方法可以是静态的,也可以是非静态的
先生,请添加此依赖项并重试
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.9</version>
</dependency>
com.squareup.okhttp3
okhttp
3.14.9
如果应用程序存在依赖项冲突,则将其添加到
要解决这些问题,请执行以下操作:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.14.9</version>
</dependency>
</dependencies>
</dependencyManagement>
com.squareup.okhttp3
okhttp
3.14.9
Java您使用的是哪个版本?请分享您的main()
方法。签名正确吗?类似于publicstaticvoidmain(String[]args)
。修改问题以添加main方法。请共享完整的pom.xmlJava,您使用的是哪个版本?请共享您的main()
方法。签名正确吗?类似于publicstaticvoidmain(String[]args)
。修改了问题以添加main方法。请共享完整的pom.xml。已经尝试过了。不工作。我没有直接使用okhttp3。我正在调用microsoft graph api,在某种程度上,api正在使用okhttp3。是的,正确!请检查依赖关系树并找到okhttp?的版本。这是我使用依赖关系树找到的版本:com.squareup.okhttp3:okhttp:jar:3.9.0:compile您使用的是哪个版本的java?我使用的是java 8已经尝试过了。不工作。我没有直接使用okhttp3。我正在调用microsoft graph api,在某种程度上,api正在使用okhttp3。是的,正确!请检查依赖关系树并找到okhttp?的版本。这是我使用依赖关系树找到的版本:com.squareup.okhttp3:okhttp:jar:3.9.0:compile您使用的是哪个版本的java?我使用的是java 8