我如何用Java做到这一点?
import requests
params = {
"api_key": "asdfg_54321",
"format": "json"
}
r = requests.get('https://www.parsehub.com/api/v2/projects/qwertyuiop/last_ready_run/data', params=params)
print(r.text)
我需要以JSON文件的形式访问在线API,我可以在Python中这样做,但我需要android studio应用程序的数据,所以我必须弄清楚如何使用API访问URL密钥作为Java的权限而已。
答案 0 :(得分:0)
确保解析$ {PROJECT_TOKEN},$ {API_KEY}和$ {FORMAT}变量
public static void getResultOfLastReadyRun() throws IOException {
URL url = new URL("https://www.parsehub.com/api/v2/projects/${PROJECT_TOKEN}/last_ready_run/data?api_key=${API_KEY}&format=${FORMAT}");
try(Scanner sc = new Scanner(new GZIPInputStream(url.openStream()))) {
while (sc.hasNext()) {
System.out.println(sc.nextLine());
}
}
}