G Suite帐户获取报告Java示例问题

时间:2020-04-11 02:30:05

标签: java gson google-admin-sdk google-reporting-api

我正在尝试使用此api来获取Java的报告,这是链接

https://developers.google.com/admin-sdk/reports/v1/appendix/activity/meet

这是我现在正在使用的

public static String getGraph() {
    String PROTECTED_RESOURCE_URL = "https://www.googleapis.com/admin/reports/v1/activity/users/all/applications/meet?eventName=call_ended&maxResults=10&access_token=";
        String graph = "";
    try {
        URL urUserInfo = new URL(PROTECTED_RESOURCE_URL + "access_token");
        HttpURLConnection connObtainUserInfo = (HttpURLConnection) urUserInfo.openConnection();
        if (connObtainUserInfo.getResponseCode() == HttpURLConnection.HTTP_OK) {
            StringBuilder sbLines = new StringBuilder("");

            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(connObtainUserInfo.getInputStream(), "utf-8"));
            String strLine = "";
            while ((strLine = reader.readLine()) != null) {
                sbLines.append(strLine);
            }
            graph = sbLines.toString();
        }
    } catch (IOException ex) {
            x.printStackTrace();
    }
    return graph;
}

我很确定这不是一个聪明的方法,并且我得到的字符串非常复杂,是否有任何我可以直接获取数据而不是使用java起源httpRequest的jave示例

或者,是否存在可以导入的类以将json字符串切换为对象!?

有人可以帮忙吗?!

我已经尝试了很多天了!

谢谢!

0 个答案:

没有答案