gpt4 book ai didi

java - 谷歌分析的 setCredentialStore 方法的替代方法

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:06:58 24 4
gpt4 key购买 nike

我使用以下代码授权安装的应用程序访问用户的 protected 数据。

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 的替代代码被弃用了。

最佳答案

从之前的答案中添加:

如果要指定文件名,可以使用DataStore<StoredCredential> dataStore = dataStoreFactory.getDataStore("specificFilename"); , 然后在 GoogleAuthorizationCodeFlow使用 .setCredentialDataStore(dataStore)方法。

关于java - 谷歌分析的 setCredentialStore 方法的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20144375/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com