我正在尝试使用GoogleCredential.Builder()创建一个GoogleCredential对象。我不断收到“找不到文件”异常,我尝试将文件放置在多个位置。应用程序为什么找不到文件?该文件是res / raw文件夹。
userEmail=" xxxxxxx.iam.gserviceaccount.com";
SERVICE_ACCOUNT_PKCS12_FILE= new File( "/res/raw/file.p12");
HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();
String[] scopesArray = {"https://spreadsheets.google.com/feeds", "https://spreadsheets.google.com/feeds/spreadsheets/private/full", "https://docs.google.com/feeds"};
final List SCOPES = Arrays.asList( scopesArray);
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(userEmail)
.setServiceAccountScopes(SCOPES)
.setServiceAccountPrivateKeyFromP12File( SERVICE_ACCOUNT_PKCS12_FILE )
.build();
错误是:System.err:java.io.FileNotFoundException:file.p12:打开失败:ENOENT(没有这样的文件或目录) 在libcore.io.IoBridge.open(IoBridge.java:487) 在java.io.FileInputStream。(FileInputStream.java:76) com.google.api.client.googleapis.auth.oauth2.GoogleCredential $ Builder.setServiceAccountPrivateKeyFromP12File(GoogleCredential.java:715)