• Trong thời gian này, bạn không thể tạo bài mới, đăng comment, hay tạo tài nguyên mới để diễn đàn dọn dẹp nội dung.
    Diễn đàn sẽ sớm mở trở lại, chi tiết hãy theo dõi tại Discord
anhcraft

Hướng dẫn Sử dụng API Tài nguyên v2 của minecraftvn.net

  • Người tạo chủ đề Người tạo chủ đề anhcraft
  • Ngày gửi Ngày gửi
Mới xin update cái API :') Cái cũ dùng chán quá
Link tới API: https://minecraftvn.net/resource.api?id=XXX
Trong đó XXX là ID tài nguyên của bạn
VD Tài nguyên của bạn là https://minecraftvn.net/resources/oregen4.1243/ thì 1243 là ID

API sẽ trả về dạng JSON. Gồm các trường:

codeIntegerTrạng thái (1 = thành công; 0 = thất bại)
versionStringPhiên bản mới nhất
download_countIntegerLượt tải của phiên bản mới nhất
VD với tài nguyên ở trên:
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();
        }
    }
}
 
Link tới API: https://minecraftvn.net/resource.api?id=XXX
Trong đó XXX là ID tài nguyên của bạn
VD Tài nguyên của bạn là https://minecraftvn.net/resources/oregen4.1243/ thì 1243 là ID

API sẽ trả về dạng JSON. Gồm các trường:

codeIntegerTrạng thái (1 = thành công; 0 = thất bại)
versionStringPhiên bản mới nhất
download_countIntegerLượt tải của phiên bản mới nhất
VD với tài nguyên ở trên:
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();
        }
    }
}
sao cái download_count k để long nhỉ? lượng download khá nhiều vượt xa mức int thì sao?
 
Nội dung tương tự Xem nhiều nhất Xem thêm

Thống kê nội dung

Tạo
anhcraft,
Trả lời lần cuối từ
anhcraft,
Trả lời
9
Lượt xem
1,054
Quay lại
Trên cùng