Integrate Dropbox in android app, but without login popup

回眸只為那壹抹淺笑 提交于 2019-11-30 12:29:26

问题


I want to use the dropbox in my application.I developed a sample application for upload and download files and it ask for authentication.

But I don't want to open login popup.

Is it possible access the dropbox by other users using default account(single account) login details? So any user can use dropbox directly without login popup.


回答1:


How to set access user access token pair manually.

     AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
     AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);
     if (mDBApi == null) {
        mDBApi = new DropboxAPI<AndroidAuthSession>(session);

//  mDBApi.getSession().startAuthentication(Main.this);  //kicks off the web-based authentication
      //you'll have to use the web-based authentication UI one-time to get the ######### values
        String token_key="#########";  
        String token_seceret="#########";
        AccessTokenPair tokens=new AccessTokenPair(token_key,token_seceret);
        mDBApi.getSession().setAccessTokenPair(tokens);     
  //  boolean v=mDBApi.getSession().authenticationSuccessful(); 
    }

First time i run application in debug mode with break point i get the token key and token secret of by entering valid log in detail.and saved(noted) that credential and after that i set them manually as above code then can be log in successfully.




回答2:


Yes. Have a look at their example app DBRoulette.




回答3:


Please download the project from the below link name as DBRoulette

https://www.dropbox.com/developers/core

And create an app in https://www.dropbox.com/developers and get the api key and secret and add this both in DBRoulette.java and in AndroidManifest.xml ...it works..




回答4:


In onCreate() write

AppKeyPair pair = new AppKeyPair(ACCESS_KEY, ACCESS_SECRET);
    session = new AndroidAuthSession(pair, AccessType.APP_FOLDER);
    dropbox = new DropboxAPI<AndroidAuthSession>(session);

    SharedPreferences prefs = getSharedPreferences(DROPBOX_NAME, 0);
    String key = prefs.getString(ACCESS_KEY, null);
    String secret = prefs.getString(ACCESS_SECRET, null);
    if (key != null && secret != null) {
        Log.d("key secret", key + "    " + secret);
        AccessTokenPair token = new AccessTokenPair(key, secret);
        dropbox.getSession().setAccessTokenPair(token);
    }
    if (key == null && secret == null)
            dropbox.getSession().startAuthentication(DropboxActivity.this);

And in onResume() write

if (dropbox.getSession().isLinked()) {
        try {
            loggedIn(true);
            doAction();
        } catch (IllegalStateException e) {
            Toast.makeText(this, "Error during Dropbox authentication",
            Toast.LENGTH_SHORT).show();
        }

        } else if (dropbox.getSession().authenticationSuccessful()) {
            try {
                session.finishAuthentication();
                TokenPair tokens = session.getAccessTokenPair();
                SharedPreferences prefs = getSharedPreferences(DROPBOX_NAME, 0);
                Editor editor = prefs.edit();
                editor.putString(ACCESS_KEY, tokens.key);
                editor.putString(ACCESS_SECRET, tokens.secret);
                editor.commit();

                loggedIn(true);
                doAction();

            } catch (IllegalStateException e) {
                Toast.makeText(this, "Error during Dropbox authentication",
                        Toast.LENGTH_SHORT).show();
            }

        }

It worked fine for me



来源:https://stackoverflow.com/questions/15636457/integrate-dropbox-in-android-app-but-without-login-popup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!