Java 用于谷歌分析的setCredentialStore方法的替代方法
我使用以下代码授权安装的应用程序访问用户受保护的数据Java 用于谷歌分析的setCredentialStore方法的替代方法,java,google-analytics-api,Java,Google Analytics Api,我使用以下代码授权安装的应用程序访问用户受保护的数据 private Analytics iniAnalytics (String secureFolder) { try { HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JsonFactory jasonFactory = new JacksonFactory();
private Analytics iniAnalytics (String secureFolder) {
try {
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jasonFactory = new JacksonFactory();
/** Authorizes the installed application to access user's protected data. */
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(
jasonFactory,
new FileReader(secureFolder + "client_secrets.json"));
FileCredentialStore credentialStore = new FileCredentialStore(
new File(secureFolder, "analytics.json"),
jasonFactory);
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport,
jasonFactory,
clientSecrets,
Collections.singleton(AnalyticsScopes.ANALYTICS_READONLY))
.setCredentialStore(credentialStore).build();
Credential credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver())
.authorize("user");
return new Analytics.Builder(httpTransport, jasonFactory, credential)
.setApplicationName("myapp/Analytics/2.0").build();
} catch (GeneralSecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
上述方法setCredentialStore的哪些替代代码被弃用。使用
FileDataStoreFactory fdsf=new FileDataStoreFactory(String whereToSave)
然后在GoogleAuthorizationCodeFlow
中使用.setDataStoreFactory(fdsf)
方法
任何后续启动此方法都将自动检查您为storedCredential文件指定的位置,并使用该位置为您提供所需的凭据。从上一个答案添加: 如果要指定文件名,可以使用
DataStore DataStore=dataStoreFactory.getDataStore(“specificFilename”)
,然后在GoogleAuthorizationCodeFlow
中使用.setCredentialDataStore(数据存储)
方法