Android在使用谷歌日历API时为IOException提供``无法创建目录:/令牌'' [英] Android giving IOException with 'unable to create directory: /tokens' when using google calendar api
问题描述
尝试在Android中实现Calendar Quickstart API,但是当我如所示声明令牌时.
private final String TOKENS_DIRECTORY_PATH = "tokens";
Trying to implement the Calendar Quickstart API into Android but when I declare tokens as demonstrated.
private final String TOKENS_DIRECTORY_PATH = "tokens";
然后在构建器中使用该字符串
That String is then used in the builder
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
.setAccessType("offline")
.build();
但是,当设置DataStoreFactory
java.io.IOException: unable to create directory: /tokens
是否有其他方法可以创建可以使用的目录?还是必须更改TOKENS_DIRECTORY_PATH
的文件路径?
Is there a different method to creating a directory that will work? or must I change the file path of TOKENS_DIRECTORY_PATH
?
推荐答案
我使用了这段代码.
File tokenFolder = new File(Environment.getExternalStorageDirectory() +
File.separator + TOKENS_DIRECTORY_PATH);
if (!tokenFolder.exists()) {
tokenFolder.mkdirs();
}
flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(new FileDataStoreFactory(tokenFolder))
.setAccessType("offline")
.build();
并获得Android清单文件中外部存储的权限
And get permissions to external storage in Android manifest file
编辑:在Google API文档中为Java指定的方法似乎不适用于Android.将此 github项目用作将Google API集成到Android应用程序中的指南.
The methods specified in Google API documentation for Java doesn't seem to work well for Android. Use this github project as a guide for implementing integrating Google APIs into Android applications.
这篇关于Android在使用谷歌日历API时为IOException提供``无法创建目录:/令牌''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!