gpt4 book ai didi

尝试创建 GoogleCredential 时出现 java.io.FileNotFoundException

转载 作者:行者123 更新时间:2023-12-02 13:06:02 26 4
gpt4 key购买 nike

我正在尝试在我的 Android 应用程序中运行此代码:

    public Bigquery createAuthorizedClient() throws IOException {
final List SCOPE = Arrays.asList("https://www.googleapis.com/auth/bigquery");
HttpTransport transport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleCredential credential = new GoogleCredential();
try{
File file = new File("C:\\testprojectbigquery\\UkrBikeApp-ff55878cb577.p12");
credential = new GoogleCredential.Builder().setTransport(transport)
.setJsonFactory(jsonFactory)
.setServiceAccountId("bigquerymain@ukrbikeapp.iam.gserviceaccount.com")
.setServiceAccountScopes(SCOPE)
.setServiceAccountPrivateKeyFromP12File(file)
.build();
}
catch (Exception e){
System.out.println("e = " + e);
}


if (credential.createScopedRequired()) {
credential = credential.createScoped(BigqueryScopes.all());
}

return new Bigquery.Builder(transport, jsonFactory, credential)
.setApplicationName("Bigquery Samples")
.build();
}

但每次我得到:

java.io.FileNotFoundException

然后我尝试创建InputStream,但没有改变情况:

        AssetManager am = getAssets();
InputStream inputStream = am.open("C:\\testprojectbigquery\\UkrBikeApp-ff55878cb577.p12");
File file = createFileFromInputStream(inputStream);

最佳答案

您正在为 Android 设备编码,而 Android 没有 C 驱动器!要读取此文件,您必须将文件放入项目的assets文件夹中,然后从此文件夹中读取。这是一个example of reading assets

关于尝试创建 GoogleCredential 时出现 java.io.FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44122191/

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