Imgur.com là kho hình miễn phí với tốc độ truy cập cao. đây cũng là kho hình chính của hệ thống website bán hàng online chuyên nghiệp wizkool.com
Nay mình giới thiệu các IT cách tích hợp và truy vấn lấy hình từ imgur.com bằng token và java
Bước 1: link đăng nhập lấy token https://api.imgur.com/oauth2/authorize?client_id={idapp}&response_type=token
với {idapp} là mã ứng dụng trên imgur.com lấy tại https://imgur.com/account/settings/apps
Nay mình giới thiệu các IT cách tích hợp và truy vấn lấy hình từ imgur.com bằng token và java
Bước 1: link đăng nhập lấy token https://api.imgur.com/oauth2/authorize?client_id={idapp}&response_type=token
với {idapp} là mã ứng dụng trên imgur.com lấy tại https://imgur.com/account/settings/apps
Bước 2: Click vào edit của Redirect để chỉnh link trả về token sau khi xử lý xong
Bước 3: sau khi có token thì lấy hình
Tất cả hình: https://api.imgur.com/3/account/me/images/count
Lấy 1 hình: https://api.imgur.com/3/account/me/images/
Tạo code gửi:
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
try {
builder.setHeader("Content-Type", "application/json");
builder.setHeader("authorization", "Bearer " + token);
builder.sendRequest("", new RequestCallback() {
public void onError(Request request, Throwable exception) {
Quảng cáo
// code omitted for clarity
}
public void onResponseReceived(Request request, Response response) {
double count_data_add = dataJson(libJson.getJson(response.getText()));
// run is start = begin
if (data_imgur_page_max == 0 && count_data_add > 0)
data_imgur_page_max = count_data_add;
data_imgur_data_down += count_data_add;
if (data_imgur_data_down < data_imgur_count_total) {
Quảng cáo
// lap lai va down them
new Timer() {
@override
public void run() {
callImg(token, page_current + 1);
}
}.schedule(200);
} else {
MaterialToast.fireToast(libLang.getLang("imgur_load_final", lang_default));
// has search
if (!img_search.getValue().equals(""))
recallSearchDialogSelectImgGoogleDriver();
}
}
});
} catch (RequestException e) {
Window.alert("Failed to send the request: " + e.getMessage());
}