-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCallAPIExample.java
43 lines (37 loc) · 1.46 KB
/
CallAPIExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.ecnu.example;
import com.alibaba.fastjson.JSONObject;
import com.ecnu.OAuth2Client;
import com.ecnu.common.OAuth2Config;
import java.util.List;
/**
* @description CallAPI Example
*/
public class CallAPIExample {
public static void main(String[] args) throws Exception {
/*
public class OAuth2Config {
private String clientId; // 必须
private String clientSecret; // 必须
private String baseUrl; // 默认 https://api.ecnu.edu.cn
private List<String> scopes; //默认 ["ECNU-Basic"]
private Integer timeout; //默认10秒
private Boolean debug; //默认 false, 如果开启 debug,会打印出请求和响应的详细信息,对于数据同步类接口而言可能会非常大
}
*/
OAuth2Config cf = OAuth2Config.builder()
.clientId("clientId")
.clientSecret("clientSecret")
.debug(true)
.build();
OAuth2Client client = OAuth2Client.getClient();
client.initOAuth2ClientCredentials(cf);
String url = "https://api.ecnu.edu.cn/api/v1/sync/fakewithts?ts=0&pageNum=1&pageSize=1";
// -------test callApi----------
List<JSONObject> response = client.callAPI(url, "GET", null, null, JSONObject.class);
if (response != null) {
System.out.println(response);
} else {
System.out.println("callAPI failed!");
}
}
}