替代google分析的setCredentialStore方法 [英] Alternative to setCredentialStore method for google analytics
本文介绍了替代google分析的setCredentialStore方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码授权已安装的应用程序访问用户的受保护数据。
I am using the following code for Authorizes the installed application to access user's protected data.
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的上述替代代码已被弃用。
What alternative code for above as method setCredentialStore get deprecated.
推荐答案
从上一个回答添加:
如果要指定文件名,可以使用 DataStore< StoredCredential> dataStore = dataStoreFactory.getDataStore(specificFilename);
,然后在 GoogleAuthorizationCodeFlow
中使用 .setCredentialDataStore(dataStore)
方法。
If you want to specify the filename, you can use DataStore<StoredCredential> dataStore = dataStoreFactory.getDataStore("specificFilename");
,then in GoogleAuthorizationCodeFlow
use the .setCredentialDataStore(dataStore)
method.
这篇关于替代google分析的setCredentialStore方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文