我正在尝试为get和post方法使用microsoftgraphapi。java代码:
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/请求$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>
请帮我解决这个问题?
这是主要方法:
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");
}
1条答案
按热度按时间mum43rcc1#
看到异常(nosuchmethoderror),您找到了类,因此在类路径中有一个okhttp。我的猜测是使用了一个旧版本的okhttp(可能是因为其他依赖关系),并且出现了依赖关系冲突。
当java代码试图调用类中不存在的方法时,会出现java.lang.nosucmethoderror,该方法可以是静态方法,也可以是非静态方法。
先生,请添加此依赖项并重试。
如果应用程序存在依赖项冲突,请将此添加到pom.xml中以解决这些冲突: