[英]Google Dialogflow: The Application Default Credentials are not available
[英]The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise - java android
我使用谷歌驅動器制作一個應用程序來將用戶的文件存儲到他們的谷歌驅動器我遵循谷歌開發者指南https://developers.google.com/drive/api/guides/about-sdk當我按下按鈕上傳我的文件我得到了標題錯誤這是
try {
// Load pre-authorized user credentials from the environment.
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
.createScoped(Arrays.asList(DriveScopes.DRIVE_FILE));
HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
credentials);
Drive service = new com.google.api.services.drive.Drive.Builder(new NetHttpTransport(),
GsonFactory.getDefaultInstance(),
requestInitializer)
.setApplicationName(getString(R.string.app_name))
.build();
File fileMetaDate = new File();
fileMetaDate.setName(getString(R.string.db_name_lists));
File file1 = service.files().create(fileMetaDate, fileContent)
.setFields("id")
.execute();
Toast.makeText(this, file1.getId() + " has been created", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
應用程序默認憑據不可用。 如果在 Google Compute Engine 中運行,它們就可用。 否則 - java android
使用
GoogleCredentials credentials = GoogleCredentials.getApplicationDefault()
您必須定義環境變量GOOGLE_APPLICATION_CREDENTIALS
指向定義憑據的文件。
否則,您可以按照Google 驅動器 java 快速入門中所示的方式進行操作
private static final String CREDENTIALS_FILE_PATH = "/credentials.json";
InputStream in = DriveQuickstart.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
if (in == null) {
throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
}
GoogleClientSecrets clientSecrets =
GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.