当我尝试在谷歌存储上列出文件时,我收到此错误
"code" : 400,此 API 的 v1beta2 版本不再可用。请使用 JSON API v1 重试。要为您的项目申请临时恢复,请访问https://docs.google.com/forms/d/1isIxBZg3rsQbDN_TOalZaz1WT_ebJchsrlv-Qr_r9mY/viewform?entry.244568692=773473680319&entry.176324201=v1beta2&entry.1071661541-Qr_r9mY/
如何在我的 android 应用程序中使用 JSON API v1?
这是我的代码
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
Storage storage = getStorage();
Storage.Objects.List listObjects = storage.objects().list(mContext.getString(R.string.storage_bucket_name));
com.google.api.services.storage.model.Objects objects;
do {
objects = listObjects.execute();
List<StorageObject> items = objects.getItems();
if (null == items) {
System.out.println("There were no objects in the given bucket; try adding some and re-running.");
break;
}
for (StorageObject object : items) {
System.out.println(object.getName() + " (" + object.getSize() + " bytes)");
}
listObjects.setPageToken(objects.getNextPageToken());
} while (null != objects.getNextPageToken());
} catch (IOException e) {
e.printStackTrace();
} catch (GeneralSecurityException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
在这一行中抛出异常: objects = listObjects.execute();
private Storage getStorage() throws Exception {
if (sStorage == null) {
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
List<String> scopes = new ArrayList<String>();
scopes.add(StorageScopes.DEVSTORAGE_FULL_CONTROL);
AssetManager am = mContext.getAssets();
InputStream inputStream = am.open(mContext.getResources().getString(R.string.storage_p12_key_path)); // you
File file = UtilsMedia.stream2file(inputStream);
GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory)
.setServiceAccountId(mContext.getResources().getString(R.string.storage_mail_id))
.setServiceAccountScopes((scopes)).setServiceAccountPrivateKeyFromP12File(file). build();
sStorage = new Storage.Builder(httpTransport, jsonFactory, credential).setApplicationName("Veolia e-fsm").build();
}
return sStorage;
}
非常感谢您的帮助