tamtoum1987
tamtoum1987

Reputation: 2057

android acces google storage Version v1beta2 of this API is no longer available. Please try again using JSON API v1

When i try to list files on google storage i get this error

"code" : 400, Version v1beta2 of this API is no longer available. Please try again using JSON API v1. To request temporary reinstatement for your project, please visit https://docs.google.com/forms/d/1isIxBZg3rsQbDN_TOalZaz1WT_ebJchsrlv-Qr_r9mY/viewform?entry.244568692=773473680319&entry.176324201=v1beta2&entry.1071661541-Qr_r9mY/prefill

how can i use JSON API v1 in my android application ?

here is my code

 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();
            }

The exceptions is throwen in this line: 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;
     }

ny help would be greatly appreciated

Upvotes: 1

Views: 214

Answers (1)

Brandon Yarbrough
Brandon Yarbrough

Reputation: 38379

What version of the storage client are you using?

Are you using Maven? Perhaps the google-api-services-storage package? You may have accidentally chosen a "v1beta2" version by mistake. I believe the current version is "v1-rev35-1.20.0".

"v1beta1" and "v1beta2" are old, beta versions of this API and are no longer usable.

Upvotes: 2

Related Questions