我已尽力使这段代码正常工作,但是,唉!肯定有什么问题。我试图列出 Cloudinary 中的所有 public_ids 。但它总是打印 null。下面是代码 -
import java.util.HashMap;
import java.util.Map;
import com.cloudinary.Api;
import com.cloudinary.Cloudinary;
import com.cloudinary.utils.ObjectUtils;
public class AllResources {
@SuppressWarnings("unchecked")
public static void main(String[] Args) {
Map<String, String> config = new HashMap<>();
config.put("cloud_name", "*******");
config.put("api_key", "**************");
config.put("api_secret", "***************************");
Cloudinary c = new Cloudinary(config);
Api api = c.api();
try {
Map<String, Object> result = api.resources(ObjectUtils.asMap());
System.out.println(result.get("public_id"));
} catch (Exception e) {
e.printStackTrace();
}
}
}
您可以执行以下操作:
String nextCursor = null;
do {
result = api.resources(ObjectUtils.asMap("max_results", 500, "next_cursor", nextCursor));
nextCursor = result.get("next_cursor");
for (Map.Entry<String, Object> data : result.entrySet()) {
String key = data.getKey().toString();
Object value = data.getValue();
System.out.println(key + value);
}
} while (nextCursor != null);
我是一名优秀的程序员,十分优秀!