android acces google存储此API的v1beta2版本不再可用。请使用JSON API v1再试一次

时间:2015-06-02 10:07:33

标签: android google-cloud-storage json-api

当我尝试在Google存储空间中列出文件时,我收到此错误

"代码" :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/prefill

如何在我的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;
     }

非常感谢你的帮助

1 个答案:

答案 0 :(得分:2)

您使用的是哪个版本的存储客户端?

你在使用Maven吗?也许google-api-services-storage包?您可能不小心选择了&#34; v1beta2&#34;版本错误。我相信目前的版本是&#34; v1-rev35-1.20.0&#34;。

&#34; v1beta1&#34;和&#34; v1beta2&#34;是此API的旧版本,不再可用。