- Tham gia
- 18/09/2016
- Bài viết
- 3,165
Mới xin update cái API :') Cái cũ dùng chán quá
Link tới API: minecraftvn.netXXX
Trong đó XXX là ID tài nguyên của bạn
VD Tài nguyên của bạn là minecraftvn.netoregen4.1243/ thì 1243 là ID
API sẽ trả về dạng JSON. Gồm các trường:
VD với tài nguyên ở trên:
Trong trường hợp bị lỗi thì code=0
Code Java mẫu để dùng API này:
Link tới API: minecraftvn.netXXX
Trong đó XXX là ID tài nguyên của bạn
VD Tài nguyên của bạn là minecraftvn.netoregen4.1243/ thì 1243 là ID
API sẽ trả về dạng JSON. Gồm các trường:
| code | Integer | Trạng thái (1 = thành công; 0 = thất bại) |
| version | String | Phiên bản mới nhất |
| download_count | Integer | Lượt tải của phiên bản mới nhất |
JSON:
{"code":1,"version":"1.4.5","download_count":169}
Trong trường hợp bị lỗi thì code=0
JSON:
{"code":0}
Code Java mẫu để dùng API này:
Java:
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class Main {
public static void main(String[] args){
try {
int resource_id = 1243;
URL url = new URL("https://minecraftvn.net/resource.api?id="+resource_id);
String json = IOUtils.toString(url, StandardCharsets.UTF_8);
JsonObject object = new Gson().fromJson(json, JsonObject.class);
int code = object.getAsJsonPrimitive("code").getAsInt();
if(code == 1){
String version_str = object.getAsJsonPrimitive("version").getAsString();
int download_count = object.getAsJsonPrimitive("download_count").getAsInt();
System.out.println(String.format("Phiên bản: %s | Lượt tải: %d", version_str, download_count));
} else System.out.println("Không thể kiểm tra cập nhật!");
} catch (IOException e) {
e.printStackTrace();
}
}
}






