- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
源代码:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessTokenRequest;
import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAuthorizationRequestUrl;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.analytics.Analytics;
import com.google.api.services.analytics.Analytics.Data.Ga.Get;
import com.google.api.services.analytics.model.GaData;
import com.google.api.services.analytics.model.GaData.ColumnHeaders;
import com.google.api.services.analytics.model.Profile;
import com.google.api.services.analytics.model.Profiles;
import com.google.api.services.analytics.model.Segment;
import com.google.api.services.analytics.model.Segments;
/**
* This class displays an example of a client application using the Google API
* to access the Google Analytics data
*
*
*
*/
@SuppressWarnings("deprecation")
public class GoogleAnalyticsExample {
private static final String SCOPE = "https://www.googleapis.com/auth/analytics.readonly";
private static final String REDIRECT_URL = "urn:ietf:wg:oauth:2.0:oob";
private static final HttpTransport netHttpTransport = new NetHttpTransport();
private static final JacksonFactory jacksonFactory = new JacksonFactory();
private static final String APPLICATION_NAME = "familys";
// FILL THESE IN WITH YOUR VALUES FROM THE API CONSOLE
private static final String CLIENT_ID = "XXXXXX";
private static final String CLIENT_SECRET = "XXXXXX";
public static void main(String args[]) throws HttpResponseException,
IOException {
// Generate the URL to send the user to grant access.
GoogleCredential credential = null;
String authorizationUrl = new GoogleAuthorizationRequestUrl(CLIENT_ID,
REDIRECT_URL, SCOPE).build();
System.out.println("Go to the following link in your browser:");
System.out.println(authorizationUrl);
// Get authorization code from user.
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("What is the authorization code?");
String authorizationCode = null;
try {
authorizationCode = in.readLine();
} catch (IOException ioe) {
ioe.printStackTrace();
}
// Use the authorisation code to get an access token
AccessTokenResponse response = null;
try {
response = new GoogleAccessTokenRequest.GoogleAuthorizationCodeGrant(
netHttpTransport, jacksonFactory, CLIENT_ID, CLIENT_SECRET,
authorizationCode, REDIRECT_URL).execute();
} catch (IOException ioe) {
ioe.printStackTrace();
}
// Use the access token to get a new GoogleAccessProtectedResource.
GoogleAccessProtectedResource googleAccessProtectedResource = new GoogleAccessProtectedResource(
response.accessToken, netHttpTransport, jacksonFactory,
CLIENT_ID, CLIENT_SECRET, response.refreshToken);
// Instantiating a Service Object
// Analytics analytics = Analytics
// .Builder(netHttpTransport, jacksonFactory)
// .setHttpRequestInitializer(googleAccessProtectedResource)
// .setApplicationName(APPLICATION_NAME).build();
Analytics analytics = new Analytics.Builder(netHttpTransport, jacksonFactory, credential)
.setHttpRequestInitializer(googleAccessProtectedResource).setApplicationName(APPLICATION_NAME).build();
analytics.getApplicationName();
System.out.println("Application Name: "
+ analytics.getApplicationName());
// Get profile details
Profiles profiles = analytics.management().profiles()
.list("~all", "~all").execute();
displayProfiles(profiles, analytics);
// Get the segment details
Segments segments = analytics.management().segments().list().execute();
displaySegments(segments);
}
/**
* displayProfiles gives all the profile info for this property
* @param profiles
* @param analytics
*/
public static void displayProfiles(Profiles profiles, Analytics analytics) {
for (Profile profile : profiles.getItems()) {
System.out.println("Account ID: " + profile.getAccountId());
System.out
.println("Web Property ID: " + profile.getWebPropertyId());
System.out.println("Web Property Internal ID: "
+ profile.getInternalWebPropertyId());
System.out.println("Profile ID: " + profile.getId());
System.out.println("Profile Name: " + profile.getName());
System.out.println("Profile defaultPage: "
+ profile.getDefaultPage());
System.out.println("Profile Exclude Query Parameters: "
+ profile.getExcludeQueryParameters());
System.out.println("Profile Site Search Query Parameters: "
+ profile.getSiteSearchQueryParameters());
System.out.println("Profile Site Search Category Parameters: "
+ profile.getSiteSearchCategoryParameters());
System.out.println("Profile Currency: " + profile.getCurrency());
System.out.println("Profile Timezone: " + profile.getTimezone());
System.out.println("Profile Updated: " + profile.getUpdated());
System.out.println("Profile Created: " + profile.getCreated());
try {
/**
* The get method follows the builder pattern, where all
* required parameters are passed to the get method and all
* optional parameters can be set through specific setter
* methods.
*/
// Possible to Build API Query with various criteria as below
Get apiQuery = analytics.data().ga()
.get("ga:" + profile.getId(), // Table ID =
// "ga"+ProfileID
"2013-03-21", // Start date
"2013-05-04", // End date
"ga:visits"); // Metrics
apiQuery.setDimensions("ga:source,ga:medium");
apiQuery.setFilters("ga:medium==referral");
apiQuery.setSort("-ga:visits");
apiQuery.setSegment("gaid::-11");
apiQuery.setMaxResults(100);
// Make Data Request
GaData gaData = apiQuery.execute();
if (profile.getId() != null) {
retrieveData(gaData);
}
} catch (IOException e) {
System.out.println("Inside displayProfile method");
e.printStackTrace();
}
}
}
/**
* retrieveData() gets the Google Analytics user data
* @param gaData
*/
public static void retrieveData(GaData gaData) {
// Get Row Data
if (gaData.getTotalResults() > 0) {
// Get the column headers
for (ColumnHeaders header : gaData.getColumnHeaders()) {
System.out.format("%-20s",
header.getName() + '(' + header.getDataType() + ')');
}
System.out.println();
// Print the rows of data.
for (List<String> rowValues : gaData.getRows()) {
for (String value : rowValues) {
System.out.format("%-20s", value);
}
System.out.println();
}
} else {
System.out.println("No data");
}
}
/**
* displaySegments provides Segment details of the account
* @param segments
*/
public static void displaySegments(Segments segments) {
for (Segment segment : segments.getItems()) {
System.out.println("Advanced Segment ID: " + segment.getId());
System.out.println("Advanced Segment Name: " + segment.getName());
System.out.println("Advanced Segment Definition: "
+ segment.getDefinition());
}
}
}
当我运行此代码时,它可以正常工作,它会提供一个授权链接,并且我获得了授权代码,但是当我在控制台中输入授权代码时,它会给出此错误:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/api/client/http/HttpParser
at GoogleAnalyticsExample.main(GoogleAnalyticsExample.java:64)
Caused by: java.lang.ClassNotFoundException: com.google.api.client.http.HttpParser
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
最佳答案
在类路径中包含以下 jar ... google-http-client-1.5.0-beta.jar
。另外,请确保在运行和编译代码时包含确切数量的 jar。
我在我的类路径中使用了以下 jar 。大约 2-3 个 jar 可以排除在外
jdk1.6.0_21/lib/tools.jar
google-api-client-1.15.0-rc.jar
mysql-connector-java-3.1.7-bin.jar
google-api-services-analytics-v3-rev50-1.15.0-rc.jar
google-api-services-analytics-v3-rev50-1.15.0-rc-javadoc.jar
google-api-services-analytics-v3-rev50-1.15.0-rc-sources.jar
google-http-client-1.15.0-rc.jar
google-http-client-jackson2-1.15.0-rc.jar
jackson-core-2.0.5.jar
google-oauth-client-1.15.0-rc.jar
关于java - Google Analytics API-线程 "main"java.lang.NoClassDefFoundError : com/google/api/client/http/HttpParser 中出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17811950/
我已经设置了 Azure API 管理服务,并在自定义域上配置了它。在 Azure 门户中 API 管理服务的配置部分下,我设置了以下内容: 因为这是一个客户端系统,我必须屏蔽细节,但以下是基础知识:
我是一名习惯 React Native 的新程序员。我最近开始学习 Fetch API 及其工作原理。我的问题是,我找不到人们使用 API key 在他们的获取语句中访问信息的示例(我很难清楚地表达有
这里有很多关于 API 是什么的东西,但是我找不到我需要的关于插件 API 和类库 API 之间的区别。反正我不明白。 在 Documenting APIs 一书中,我读到:插件 API 和类库 AP
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve thi
我正在尝试找出设计以下场景的最佳方法。 假设我已经有了一个 REST API 实现,它将从不同的供应商那里获取书籍并将它们返回给我自己的客户端。 每个供应商都提供单独的 API 来向其消费者提供图书。
请有人向我解释如何使用 api key 以及它有什么用处。 我对此进行了很多搜索,但得到了不同且相互矛盾的答案。有人说 API key 是保密的,它从不作为通信的一部分发送,而其他人则将它发送给客户端
关闭。这个问题是opinion-based .它目前不接受答案。 想改进这个问题?更新问题,以便 editing this post 可以用事实和引用来回答它. 4年前关闭。 Improve this
谁能告诉我为什么 WSo2 API 管理器不进行身份验证?我已经设置了两个 WSo2 API Manager 1.8.0 实例并创建了一个 api。它作为原型(prototype) api 工作正常。
我在学习 DSL 的过程中遇到了 Fluent API。 我在流利的 API 上搜索了很多……我可以得出的基本结论是,流利的 API 使用方法链来使代码流利。 但我无法理解——在面向对象的语言中,我们
基本上,我感兴趣的是在多个区域设置 WSO2 API 管理器;例如亚洲、美国和欧洲。一些 API 将部署在每个区域的数据中心内,而其他 API 将仅部署在特定区域内。 理想情况下,我想要的是一个单一的
我正在构建自己的 API,供以下用户使用: 1) 安卓应用 2) 桌面应用 我的网址之一是:http://api.chatapp.info/order_api/files/getbeers.php我的
我需要向所有用户显示我的站点的分析,但使用 OAuth 它显示为登录用户配置的站点的分析。如何使用嵌入 API 实现仪表板但仅显示我的网站分析? 我能想到的最好的可能性是使用 API key 而不是客
我正在研究大公司如何管理其公共(public) API。我想到的是拥有成熟 API 的公司,例如 Google、Facebook、Twitter 和 Amazon。 这些公司向公众公开了许多不同的 A
在定义客户可访问的 API 时,以下是首选的行业惯例: a) 定义一组显式 API 方法,每个方法都有非常狭窄和特定的目的,例如: SetUserName SetUserAge Se
这在本地 deserver 和部署时都会发生。我成功地能够通过留言簿教程使用 API 资源管理器,但现在我已经创建了自己的项目并尝试访问我编写的第一个 API,它从未出现过。搜索栏旁边的黄色“正在加载
我正在尝试使用 http://ip-api.com/ api通过我的ip地址获取经度和纬度。当我访问 http://ip-api.com/json从我的浏览器或使用 curl,它以 json 格式返回
这里的典型示例是 Twitter 的 API。我从概念上理解 REST API 的工作原理,本质上它只是针对您的特定请求向他们的服务器查询,然后您会在其中收到响应(JSON、XML 等),很棒。 但是
我能想到的最好的标题,但要澄清的是,情况是这样的: 我正在开发一种类似短 url 的服务,该服务允许用户使用他们的 Twitter 帐户“登录”并发布内容。现在这项服务可以包含在 Tweetdeck
我正在设计用于管理评论和讨论线程的 API 方案。我想有一个点 /discussions/:discussionId 当您GET 时,它会返回一组评论和一些元数据。评论也许可以单独访问 /discus
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭去年。 Improve this quest
我是一名优秀的程序员,十分优秀!