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

huangapple 未分类评论45阅读模式
英文:

G suite account get report java sample question

问题

以下是翻译好的部分:

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;
}
英文:

I am trying to use this api to get report with java, and here is the link

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

and here is what i am using now

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;
}

I am pretty sure it's not a smart way to do that and the string I get is quite complex, are there any jave sample that i can get the data directly instead of using java origin httpRequest

Or, are there and class I can import to switch the json string to the object!?

Anyone can help?!

I have trying this for many days already!

Thanks!!

huangapple
  • 本文由 发表于 2020年4月11日 10:30:05
  • 转载请务必保留本文链接:https://java.coder-hub.com/61151386.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定