我正在尝试从项目的主文件夹中获取 xxxxxxxxxxxprivatekey.p12 路径。但它显示以下错误。我非常厌倦搜索解决方案。在哪里存储谷歌驱动器私钥文件以及如何获取路径。这是我的项目文件层次结构和错误详细信息的快照。任何帮助是appriciated.Thanks。这是取自这里的示例代码!
private Drive getDriveService(GoogleAccountCredential credential) {
return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential)
.build();
}
public static Drive getDriveService() throws GeneralSecurityException,
IOException, URISyntaxException {
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(DriveScopes.DRIVE)
.setServiceAccountPrivateKeyFromP12File(
new java.io.File(SERVICE_ACCOUNT_PKCS12_FILE_PATH))
.build();
Drive service = new Drive.Builder(httpTransport, jsonFactory, null)
.setHttpRequestInitializer(credential).build();
return service;
}
错误日志:
05-19 20:36:58.914: W/System.err(5175): java.io.FileNotFoundException: /xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-privatekey.p12: open failed: ENOENT (No such file or directory)
05-19 20:36:58.923: W/System.err(5175): at libcore.io.IoBridge.open(IoBridge.java:416)
05-19 20:36:58.923: W/System.err(5175): at java.io.FileInputStream.<init>(FileInputStream.java:78)
05-19 20:36:58.923: W/System.err(5175): at com.google.api.client.auth.security.PrivateKeys.loadFromP12File(PrivateKeys.java:178)
05-19 20:36:58.933: W/System.err(5175): at com.google.api.client.googleapis.auth.oauth2.GoogleCredential$Builder.setServiceAccountPrivateKeyFromP12File(GoogleCredential.java:541)
05-19 20:36:58.933: W/System.err(5175): at com.example.drivequickstart.MainActivity.getDriveService(MainActivity.java:172)
05-19 20:36:58.933: W/System.err(5175): at com.example.drivequickstart.MainActivity.onCreate(MainActivity.java:57)
05-19 20:36:58.933: W/System.err(5175): at android.app.Activity.performCreate(Activity.java:5104)
05-19 20:36:58.933: W/System.err(5175): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-19 20:36:58.933: W/System.err(5175): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-19 20:36:58.933: W/System.err(5175): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-19 20:36:58.933: W/System.err(5175): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-19 20:36:58.933: W/System.err(5175): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-19 20:36:58.943: W/System.err(5175): at android.os.Handler.dispatchMessage(Handler.java:99)
05-19 20:36:58.943: W/System.err(5175): at android.os.Looper.loop(Looper.java:137)
05-19 20:36:58.943: W/System.err(5175): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-19 20:36:58.943: W/System.err(5175): at java.lang.reflect.Method.invokeNative(Native Method)
05-19 20:36:58.943: W/System.err(5175): at java.lang.reflect.Method.invoke(Method.java:511)
05-19 20:36:58.943: W/System.err(5175): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-19 20:36:58.943: W/System.err(5175): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-19 20:36:58.953: W/System.err(5175): at dalvik.system.NativeStart.main(Native Method)
05-19 20:36:58.953: W/System.err(5175): Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
05-19 20:36:58.963: W/System.err(5175): at libcore.io.Posix.open(Native Method)
05-19 20:36:58.963: W/System.err(5175): at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
05-19 20:36:58.963: W/System.err(5175): at libcore.io.IoBridge.open(IoBridge.java:400)
05-19 20:36:58.963: W/System.err(5175): ... 19 more
05-19 20:36:59.413: D/gralloc_goldfish(5175): Emulator without GPU emulation detected.