0

My client wants me to download images from his public dropbox folder and show them in the app. (Think Wallpaper App). Is there any way to do this using the dropbox sdk for Android? Reading the documentation I could only find methods which involve the user authenticating himself and using his own dropbox account.

All I could think of was putting a text file with the links to the images and downloading it first, then parse it and download the images from the urls within it. However this still involves manual editing and updating the text file every time a new image is added.

Nima
  • 6,383
  • 7
  • 46
  • 68

2 Answers2

1

The Dropbox API is designed to be used with an authenticated user to make API calls to that specific account. If you already have publicly accessible URLs that you need to pull from, you don't need to use the API at all, and you can just download from those directly. These questions may be helpful for that:

It sounds like the remaining issue is that you perhaps don't know all of the links ahead of time, so using an index file like you mention sounds reasonable. (The API would let you list files in a folder, but it would be overkill for this particular scenario, in my opinion.)

Community
  • 1
  • 1
Greg
  • 16,359
  • 2
  • 34
  • 44
0

I have done similer kind of project few months before, get whole paths from dropbox and the latest changes. here is my code I have used. there is your answer, actually more than you want, because the code gives you latest changes of the folder ex:-deleted images

in this code I am getting all the urls of images contained in all folders, modify it as you want

imageLoadingAsyncTask = new AsyncTask<Void, Void, String[]>() {
        ArrayList<String> loadingPaths = new ArrayList<String>();
        ArrayList<String> deletedPathList = new ArrayList<String>();

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected String[] doInBackground(Void... params) {

            Log.i("start background running", "do in background...");
            Log.d(TAG, "ddd1");
            try {
                DeltaPage<Entry> deltaPage;
                // initializing cursor
                App.initializeCursor(mContext);
                do {

                    deltaPage = mApi.delta(App.getDropBoxCursor(mContext));

                    App.updateCursor(mContext, deltaPage.cursor);
                    if (!deltaPage.reset) {
                        for (DropboxAPI.DeltaEntry<DropboxAPI.Entry> entry : deltaPage.entries) {
                            if (entry.metadata != null) {
                                // if (!entry.metadata.isDeleted) {
                                // Log.d(TAG,
                                // String.format(
                                // "entry.metadata (%d) : %s",
                                // (entry.metadata.contents == null ? 0
                                // : entry.metadata.contents
                                // .size()),
                                // entry.metadata.path));
                                if (!(entry.metadata.isDir)
                                        && entry.metadata.thumbExists) {
                                    loadingPaths.add(entry.metadata.path
                                            .toLowerCase());
                                    Log.i("entry path",
                                            "entry path="
                                                    + entry.metadata.path
                                                            .toLowerCase());
                                }

                            } else {
                                deletedPathList.add(entry.lcPath
                                        .toLowerCase());
                                // filesToRemove.add(entry.lcPath);
                            }
                        }
                    } else {
                        // onDeltaLoadingListener.onReset();
                    }

                } while (deltaPage.hasMore);
            } catch (DropboxIOException e) {
                e.printStackTrace();
                i_activity_dropbox_photo_grid.putExtra("exception", "drop");
            } catch (DropboxException e) {
                e.printStackTrace();
            }
            // ---------------end checking dropbox chenges
            // ////////////////////////// _list2 =
            _list2 = new DropBoxImagePathDataAccess(mContext)
                    .getAppPathList();
            // //// }

            if (deletedPathList.size() > 0) {

                int x = 0, y = 0;
                for (String path : deletedPathList) {
                    // ////////////////////////////////////////////////////////////////////////////////////////////////
                    // path = path.replaceAll("['.]", "");

                    if (_list2.size() > 0 && _list2.contains(path)) {
                        _list2.remove(path);
                        new DropBoxImagePathDataAccess(mContext)
                                .removePath(path);
                        x = 1;
                    }
                    if (loadingPaths.size() > 0
                            && loadingPaths.contains(path)) {
                        loadingPaths.remove(path);
                    }
                    // if the user delete a whole folder
                    // following code will check folder name is contains in
                    // the paths
                    // if contains then whole part is removed, since all the
                    // folder contents also should be remove
                    for (String path1 : _list2) {
                        if (_list2.get(y).contains(path.toLowerCase())) {
                            _list2.remove(y);
                            new DropBoxImagePathDataAccess(mContext)
                                    .removePath(path1);
                        }
                        y++;
                    }
                }
            }

            // remove duplicate paths
            for (String path : _list2) {
                // /////////////////////////////////////////////////////////////////////////////////path
                // = path.replaceAll("[',,]", "");
                if (loadingPaths.contains(path)) {
                    loadingPaths.remove(path);

                }
            }
            int i = 0;
            int size = 0;

            size = _list2.size() + loadingPaths.size();
            mStrings = new String[size];
            // add old paths to mString array
            for (String path : _list2) {
                if (i < size) {
                    mStrings[i] = path;
                    i++;
                }
            }
            // add new paths to mStrings array
            ArrayList<String> updatePaths = new ArrayList<String>();
            if (loadingPaths.size() > 0) {
                for (String newpath : loadingPaths) {
                    if (!_list2.contains(newpath)) {
                        updatePaths.add(newpath);
                        mStrings[i] = newpath;
                        i++;
                    }
                }
            }

            // update shared preference
            if (updatePaths.size() > 0) {
                new DropBoxImagePathDataAccess(mContext)
                        .createPathList(updatePaths);
            }

            Log.i("mString size", "mString size=" + mStrings.length);
            return mStrings;
        }

        @Override
        protected void onPostExecute(String[] result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
            finalImageList = result;
            int i1 = 0;
            for (String path : finalImageList) {
                Log.i("final Image list", "final image list" + " i= " + i1
                        + " path= " + path);
            }
            App.DROP_BOX_ALL_PHOTO_LOCATED = true;

            i_activity_dropbox_photo_grid.putExtra("finalList", finalImageList);
            startActivity(i_activity_dropbox_photo_grid);
            overridePendingTransition(R.anim.activity_from_right,
                    R.anim.activity_to_left);
            finish();

        }
    };
Dehan Wjiesekara
  • 3,152
  • 3
  • 32
  • 46