• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DropboxAPI类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.dropbox.client2.DropboxAPI的典型用法代码示例。如果您正苦于以下问题:Java DropboxAPI类的具体用法?Java DropboxAPI怎么用?Java DropboxAPI使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DropboxAPI类属于com.dropbox.client2包,在下文中一共展示了DropboxAPI类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: isLinked

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
public boolean isLinked(Activity activity) {
		try {

		AppKeyPair appKeys = new AppKeyPair(StaticConfig.dropboxAppKey, StaticConfig.dropboxAppSecret);
		AndroidAuthSession session = new AndroidAuthSession(appKeys, AccessType.DROPBOX);
		api = new DropboxAPI<AndroidAuthSession>(session);		
//		
		KeyValueBean loginPwd = getLoginPwd(activity);
		AccessTokenPair atp = new AccessTokenPair(loginPwd.getKey(),loginPwd.getValue());
		api.getSession().setAccessTokenPair(atp);
//		return api.getSession().isLinked();
		api.metadata("/", 1, null, false, null);
		return true;
		}
		catch (DropboxException e){
			return false;
		}
		

	}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:21,代码来源:FileProvider4.java


示例2: initialize

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
private void initialize(String token) {
    LogUtil.log(getClass().getSimpleName(), "initialize()");

    AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
    AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);

    mDBApi = new DropboxAPI<>(session);

    if ( token == null )
        token = Settings.getDropboxSyncToken();

    if ( token != null )
        mDBApi.getSession().setOAuth2AccessToken(token);

    if (!doesFolderExist(getBaseFilePath())) {
        try {
            createFileStructure();
        } catch (DropboxException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:timothymiko,项目名称:narrate-android,代码行数:23,代码来源:DropboxSyncService.java


示例3: listFiles

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
public List<String> listFiles() throws Exception {
    if (authSession()) {
        try {
            List<String> files = new ArrayList<>();
            List<DropboxAPI.Entry> entries = dropboxApi.search("/", ".backup", 1000, false);
            for (DropboxAPI.Entry entry : entries) {
                if (entry.fileName() != null) {
                    files.add(entry.fileName());
                }
            }
            Collections.sort(files, new Comparator<String>() {
                @Override
                public int compare(String s1, String s2) {
                    return s2.compareTo(s1);
                }
            });
            return files;
        } catch (Exception e) {
            Log.e("Flowzr", "Dropbox: Something wrong", e);
            throw new ImportExportException(R.string.dropbox_error, e);
        }
    } else {
        throw new ImportExportException(R.string.dropbox_auth_error);
    }
}
 
开发者ID:emmanuel-florent,项目名称:flowzr-android-black,代码行数:26,代码来源:Dropbox.java


示例4: Login

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
/**
 * Have the user login to their dropbox account.
 * If the access tokens are saved from a previous
 * login, they will be used, otherwise the user
 * will have to login again.
 * 
 */
public void Login() {
	if (access_type != null) {			
 		if (!loggedIn) {
 			AndroidAuthSession session = buildSession();
 			dbApi = new DropboxAPI<AndroidAuthSession>(session);
 			if (container==null) {
 				dbApi.getSession().startAuthentication(sContainer.$formService());
 			} else {
 				dbApi.getSession().startAuthentication(container.$form());
 			}
 		}
	} else {
		Log.e(TAG, "AccessType is null! You MUST provide an AccessType to connect and login.");
	}
}
 
开发者ID:roadlabs,项目名称:alternate-java-bridge-library,代码行数:23,代码来源:DropBoxClient.java


示例5: connect

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
/**
 * Handles the authentication process.
 * The generated accessToken is saved, so that the user does not have to enter his/her credentials every time.
 */
@Override
public void connect() {
	// Start new authentication
	AndroidAuthSession mSession = new AndroidAuthSession(mAppKeys);
	
	// The DropboxAPI Instance
	mDBApi = new DropboxAPI<AndroidAuthSession>(mSession);
	
	this.accessToken = settings.getDropboxAuthToken();
	
	// When access token already exists in properties use it instead of starting new authentication
	if (accessToken.isEmpty()) {
		mDBApi.getSession().startOAuth2Authentication(activity);
	} else {
		mDBApi.getSession().setOAuth2AccessToken(accessToken);
	}
}
 
开发者ID:Rohde-Schwarz-Cybersecurity,项目名称:PanBox,代码行数:22,代码来源:DropboxConnector.java


示例6: disconnect

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
/**
 * Unlinks the app from the users dropbox.
 */
@Override
public void disconnect() {
	// Check first if application DB API link is still up!
	if(mDBApi == null) {
		// Start new authentication
		AndroidAuthSession mSession = new AndroidAuthSession(mAppKeys);
		
		// The DropboxAPI Instance
		mDBApi = new DropboxAPI<AndroidAuthSession>(mSession);
	}
	mDBApi.getSession().unlink();
	settings.setDropboxAuthToken("");
	settings.writeChanges();
	accessToken = "";
}
 
开发者ID:Rohde-Schwarz-Cybersecurity,项目名称:PanBox,代码行数:19,代码来源:DropboxConnector.java


示例7: uploadFile

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
/**
 * A helper method that uploads a file whose path is passed as parameter to Dropbox.
 *
 * @param path Path to the file that should be uploaded to Dropbox.
 * @throws FileNotFoundException If {@code file} does not exist.
 * @throws DropboxException      If a Dropbox related exception occurs.
 */
private void uploadFile(String path) throws FileNotFoundException, DropboxException {
    File file = new File(path);
    FileInputStream inputStream = null;
    try {
        inputStream = new FileInputStream(file);
        DropboxAPI.Entry response = dropboxApi.putFile('/' + file.getName(), inputStream, file.length(), null, null);
        Log.i(TAG, "uploadFile() :: The uploaded file's rev is: " + response.rev);
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:dbaldwin,项目名称:DroidMapper,代码行数:25,代码来源:DropboxUploaderThread.java


示例8: testRemoteFileMissing

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
public void testRemoteFileMissing() {
    DropboxAPI<?> dropboxapi = new DropboxAPIStub() {
        public DropboxAPI.Entry metadata(String arg0, int arg1,
                String arg2, boolean arg3, String arg4)
                throws DropboxException {
            throw notFoundException();
        }
    };

    DropboxFileDownloader downloader = new DropboxFileDownloader(
            dropboxapi, dropboxFiles1);

    downloader.pullFiles();
    assertEquals("Status should be SUCCESS", DropboxFileStatus.SUCCESS,
            downloader.getStatus());
    assertEquals("Should have 1 file", 1, downloader.getFiles().size());
    assertEquals("Status should be NOT_FOUND", DropboxFileStatus.NOT_FOUND,
            dbFile1.getStatus());
}
 
开发者ID:GoogleCloudPlatform,项目名称:endpoints-codelab-android,代码行数:20,代码来源:DropboxFileDownloaderTest.java


示例9: testRemoteFileDeleted

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
public void testRemoteFileDeleted() {
    DropboxAPI<?> dropboxapi = new DropboxAPIStub() {
        public DropboxAPI.Entry metadata(String arg0, int arg1,
                String arg2, boolean arg3, String arg4)
                throws DropboxException {
            return create_metadata(remoterev1, true);
        }
    };

    DropboxFileDownloader downloader = new DropboxFileDownloader(
            dropboxapi, dropboxFiles1);

    downloader.pullFiles();
    assertEquals("Status should be SUCCESS", DropboxFileStatus.SUCCESS,
            downloader.getStatus());
    assertEquals("Should have 1 file", 1, downloader.getFiles().size());
    assertEquals("Status should be NOT_FOUND", DropboxFileStatus.NOT_FOUND,
            dbFile1.getStatus());
}
 
开发者ID:GoogleCloudPlatform,项目名称:endpoints-codelab-android,代码行数:20,代码来源:DropboxFileDownloaderTest.java


示例10: testBothFilesMissing

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
public void testBothFilesMissing() {
    DropboxAPI<?> dropboxapi = new DropboxAPIStub() {
        public DropboxAPI.Entry metadata(String arg0, int arg1,
                String arg2, boolean arg3, String arg4)
                throws DropboxException {
            throw notFoundException();
        }
    };

    DropboxFileDownloader downloader = new DropboxFileDownloader(
            dropboxapi, dropboxFiles2);

    downloader.pullFiles();
    assertEquals("Status should be SUCCESS", DropboxFileStatus.SUCCESS,
            downloader.getStatus());
    assertEquals("Should have 2 files", 2, downloader.getFiles().size());
    assertEquals("Status should be NOT_FOUND", DropboxFileStatus.NOT_FOUND,
            dbFile1.getStatus());
    assertEquals("Status should be NOT_FOUND", DropboxFileStatus.NOT_FOUND,
            dbFile2.getStatus());
}
 
开发者ID:GoogleCloudPlatform,项目名称:endpoints-codelab-android,代码行数:22,代码来源:DropboxFileDownloaderTest.java


示例11: UploadFile

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
public UploadFile(Context context, DropboxAPI<?> api, String dropboxPath,
        File file) {
    // We set the context this way so we don't accidentally leak activities
    mContext = context.getApplicationContext();

    mFileLen = file.length();
    mApi = api;
    mPath = dropboxPath;
    mFile = file;

    mDialog = new ProgressDialog(context);
    mDialog.setMax(100);
    mDialog.setMessage("Uploading " + file.getName());
    mDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    mDialog.setProgress(0);
    mDialog.setButton("Cancel", new OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // This will cancel the putFile operation
            mRequest.abort();
        }
    });
    mDialog.show();
}
 
开发者ID:mobilars,项目名称:BLEConnect,代码行数:24,代码来源:UploadFile.java


示例12: createPhotoFolder

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
/**
 * Creates a directory for photos if one does not already exist. If the folder already exists, this call will
 * do nothing.
 *
 * @param dropboxApi the {@link DropboxAPI}.
 * @return true if the directory is created or it already exists; false otherwise.
 */
private boolean createPhotoFolder(DropboxAPI<AndroidAuthSession> dropboxApi) {
    boolean folderCreated = false;
    if (dropboxApi != null) {
        try {
            dropboxApi.createFolder(mContext.getString(R.string.wings_dropbox__photo_folder));
            folderCreated = true;
        } catch (DropboxException e) {
            // Consider the folder created if the folder already exists.
            if (e instanceof DropboxServerException) {
                folderCreated = DropboxServerException._403_FORBIDDEN == ((DropboxServerException) e).error;
            }
        }
    }
    return folderCreated;
}
 
开发者ID:groundupworks,项目名称:wings,代码行数:23,代码来源:DropboxEndpoint.java


示例13: getFilesInDir

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
public Set<String> getFilesInDir(String dirName, String query)
{
    Set<String> retVal = null;

    if( isConnected() ) {
        try {
            Log.d(TAG, "Getting files in: " + dirName);

            DropboxAPI.Entry entries = mDBApi.metadata("/" + dirName, MAX_DROPBOX_FILES, null, true, null);

            // Move list of files into hashset
            retVal = new HashSet<String>();
            for( DropboxAPI.Entry entry : entries.contents )
            {
                retVal.add( entry.fileName() );
            }
        } catch( DropboxException e )
        {
            e.printStackTrace();
        }
    }
    return retVal;
}
 
开发者ID:bright-tools,项目名称:androidphotobackup,代码行数:24,代码来源:DropBoxWrapper.java


示例14: fileExists

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
public boolean fileExists(String fileName)
{
    boolean retVal = false;
    if( isConnected() ) {
        try {
            DropboxAPI.Entry existingEntry = mDBApi.metadata("/" + fileName, 1, null, false, null);
            if ((!existingEntry.isDir) && (!existingEntry.isDeleted)) {
                retVal = true;
            }
        } catch( DropboxException e )
        {
            e.printStackTrace();
        }
    }
    return retVal;
}
 
开发者ID:bright-tools,项目名称:androidphotobackup,代码行数:17,代码来源:DropBoxWrapper.java


示例15: onCreate

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  Log.d("michael", "Dropboxclient.onCreate");

  // We create a new AuthSession so that we can use the Dropbox API.
  AndroidAuthSession session = buildSession();
  mApi = new DropboxAPI<AndroidAuthSession>(session);

  checkAppKeySetup();

  if (session.getAccessTokenPair() != null) {
    setLoggedIn(true);
    init();
  } else {
    // Start the remote authentication
    mApi.getSession().startAuthentication(DropboxClient.this);
    // Get the metadata for a directory
    setLoggedIn(mApi.getSession().isLinked());
  }
}
 
开发者ID:LiteracyBridge,项目名称:software,代码行数:23,代码来源:DropboxClient.java


示例16: getAuthInfo

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
/**
 * Starts an authentication request with Dropbox servers and gets all the
 * info you need to start authenticating a user. This call blocks for a
 * non-trivial amount of time due to a network operation.
 *
 * @param callbackUrl the URL to which Dropbox will redirect the user after
 *         he/she has authenticated on the Dropbox site.
 *
 * @return a {@link WebAuthInfo}, from which you can obtain the URL to
 *         redirect the user to and a request token + secret to log the
 *         user in later.
 *
 * @throws DropboxServerException if the server responds with an error
 *         code. See the constants in {@link DropboxServerException} for
 *         the meaning of each error code. The most common error codes you
 *         can expect from this call are 500, 502, and 503 (all for
 *         internal Dropbox server issues).
 * @throws DropboxIOException if any network-related error occurs.
 * @throws DropboxParseException if a malformed or unknown response was
 *         received from the server.
 * @throws DropboxException for any other unknown errors. This is also a
 *         superclass of all other Dropbox exceptions, so you may want to
 *         only catch this exception which signals that some kind of error
 *         occurred.
 */
public WebAuthInfo getAuthInfo(String callbackUrl)
        throws DropboxException {
    setUpToken("/oauth/request_token");

    // Request token pair was set as access token pair as they act the
    // same. Convert it here.
    AccessTokenPair accessTokenPair = getAccessTokenPair();
    RequestTokenPair requestTokenPair = new RequestTokenPair(
            accessTokenPair.key, accessTokenPair.secret);

    String[] args;
    if (callbackUrl != null) {
        args = new String[] {"oauth_token", requestTokenPair.key,
                             "oauth_callback", callbackUrl,
                             "locale", getLocale().toString()};
    } else {
        args = new String[] {"oauth_token", requestTokenPair.key,
                             "locale", getLocale().toString()};
    }

    String url = RESTUtility.buildURL(getWebServer(),
            DropboxAPI.VERSION, "/oauth/authorize", args);

    return new WebAuthInfo(url, requestTokenPair);
}
 
开发者ID:timezra,项目名称:dropbox-java-sdk,代码行数:51,代码来源:WebAuthSession.java


示例17: setUpToken

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
private Map<String, String> setUpToken(String path)
        throws DropboxException {
    HttpResponse response = RESTUtility.streamRequest(RequestMethod.GET,
            getAPIServer(), path,
            DropboxAPI.VERSION,
            new String[] {"locale", getLocale().toString()},
            this).response;
    Map<String, String> result = RESTUtility.parseAsQueryString(response);

    if (!result.containsKey("oauth_token") ||
            !result.containsKey("oauth_token_secret")) {
        throw new DropboxParseException("Did not get tokens from Dropbox");
    }

    setAccessTokenPair(new AccessTokenPair(
        result.get("oauth_token"), result.get("oauth_token_secret")));

    return result;
}
 
开发者ID:timezra,项目名称:dropbox-java-sdk,代码行数:20,代码来源:WebAuthSession.java


示例18: download

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
/**
 * Downloads the file from the given path in the Dropbox account.
 *
 * @param path
 *          the path to download the file from
 * @return the file content
 * @throws DropboxClientException
 */
public byte[] download(String path) throws DropboxClientException {
    // Connect to Dropbox
    DropboxAPI<?> client = connect();
    ByteArrayOutputStream tempOut = new ByteArrayOutputStream(INITIAL_BUFFER_SIZE);

    String fullPath = getFullPath(path);
    ProgressListener progressListener = null;

    if (logger.isDebugEnabled()) {
        progressListener = new LoggingProgressListener("Downloaded", PROGRESS_INTERVAL, fullPath);
    }

    // Download the file
    try {
        client.getFile(fullPath, null, tempOut, progressListener);
    } catch (Exception e) {
        throw new DropboxClientException("Error while trying to download file dropbox://" + uid + fullPath, e);
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Finished downloading file dropbox://" + uid + fullPath);
    }

    return tempOut.toByteArray();
}
 
开发者ID:avasquez614,项目名称:cloud-raid,代码行数:34,代码来源:DropboxClient.java


示例19: upload

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
/**
 * Uploads the file to the given path in the Dropbox account, creating it if it doesn't exist or overwriting it if it exists.
 *
 * @param path
 *          the path to upload the file to
 * @param content
 *          the file content
 * @throws DropboxClientException
 */
public void upload(String path, byte[] content) throws DropboxClientException {
    // Connect to Dropbox
    DropboxAPI<?> client = connect();
    ByteArrayInputStream tempIn = new ByteArrayInputStream(content);

    String fullPath = getFullPath(path);
    ProgressListener progressListener = null;

    if (logger.isDebugEnabled()) {
        progressListener = new LoggingProgressListener("Uploaded", PROGRESS_INTERVAL, fullPath);
    }

    // Upload the file
    try {
        client.putFileOverwrite(fullPath, tempIn, content.length, progressListener);
    } catch (Exception e) {
        throw new DropboxClientException("Error while trying to upload file dropbox://" + uid + fullPath, e);
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Finished uploading file dropbox://" + uid + fullPath);
    }
}
 
开发者ID:avasquez614,项目名称:cloud-raid,代码行数:33,代码来源:DropboxClient.java


示例20: delete

import com.dropbox.client2.DropboxAPI; //导入依赖的package包/类
/**
 * Deletes the file at the given path in the Dropbox account.
 *
 * @param path
 *          the path of the file to delete
 * @throws DropboxClientException
 */
public void delete(String path) throws DropboxClientException {
    // Connect to Dropbox
    DropboxAPI<?> client = connect();

    String fullPath = getFullPath(path);
    try {
        client.delete(fullPath);
    } catch (Exception e) {
        throw new DropboxClientException("Error while trying to delete file dropbox://" + uid + fullPath, e);
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Finished deleting file dropbox://" + uid + fullPath);
    }
}
 
开发者ID:avasquez614,项目名称:cloud-raid,代码行数:23,代码来源:DropboxClient.java



注:本文中的com.dropbox.client2.DropboxAPI类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java StreamRemoteCall类代码示例发布时间:2022-05-21
下一篇:
Java MovieHeaderBox类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap