无法使用Android上的FileDataStoreFactory为Youtube Data api v3创建目录

时间:2016-02-17 09:08:59

标签: android youtube youtube-data-api google-api-client

我试图将Youtube Data API用于我的Android项目。我想API Client Library Java现在支持Android。我跟随these samples。在我的Auth.java下面一行:

private static final String CREDENTIALS_DIRECTORY = ".oauth-credentials";
File dataDirectory = new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY);
FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(dataDirectory);

我收到了以下错误。

  

无法创建目录:/。outh-credentials

我尝试使用以下代码在SD卡中创建一个目录:

Environment.getExternalStorageDirectory().getAbsolutePath()

并授予权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

但我仍然无法创建目录。

我使用的附加版本的库:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.android.support:support-v4:23.1.1'
    compile 'com.google.apis:google-api-services-youtube:v3-rev162-1.20.0'
    compile 'com.google.oauth-client:google-oauth-client-java6:1.20.0'
    compile 'com.google.oauth-client:google-oauth-client-jetty:1.20.0'
}

1 个答案:

答案 0 :(得分:3)

试试这个: File dataDirectory = new File(getContext().getFilesDir(), CREDENTIALS_DIRECTORY);