gpt4 book ai didi

android - 使用 Dropbox REST 通过 Android 同步您的列表

转载 作者:行者123 更新时间:2023-11-30 04:23:40 25 4
gpt4 key购买 nike

我希望我的列表与保管箱 REST api 同步。 我怎样才能做到这一点。 单击按钮我正在上传内容。 但我收到 DropboxUnlinkedException

这是我的代码

 mSubmit = (Button)findViewById(R.id.auth_button);

mSubmit.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// This logs you out if you're logged in, or vice versa
// Uploading content.

AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
AndroidAuthSession session = buildSession();
mApi = new DropboxAPI<AndroidAuthSession>(session);

String fileContents = listItems.toString();

ByteArrayInputStream inputStream = new ByteArrayInputStream(fileContents.getBytes());
try {

Entry newEntry = mApi.putFile("/testing.txt", inputStream,
fileContents.length(), null, null);
Log.i("DbExampleLog", "The uploaded file's rev is: " + newEntry.rev);
} catch (DropboxUnlinkedException e) {
// User has unlinked, ask them to link again here.
Log.e("DbExampleLog", "User has unlinked.");
} catch (DropboxException e) {
Log.e("DbExampleLog", "Something went wrong while uploading.");
}
}
});


private String[] getKeys() {
// TODO Auto-generated method stub
SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS_NAME, 0);
String key = prefs.getString(ACCESS_KEY_NAME, null);
String secret = prefs.getString(ACCESS_SECRET_NAME, null);
if (key != null && secret != null) {
String[] ret = new String[2];
ret[0] = key;
ret[1] = secret;
return ret;
} else {
return null;
}

}



private AndroidAuthSession buildSession() {

AppKeyPair appKeyPair = new AppKeyPair(APP_KEY, APP_SECRET);
AndroidAuthSession session;
String[] stored = getKeys();
if (stored != null) {
AccessTokenPair accessToken = new AccessTokenPair(stored[0], stored[1]);
session = new AndroidAuthSession(appKeyPair, ACCESS_TYPE, accessToken);
} else {
session = new AndroidAuthSession(appKeyPair, ACCESS_TYPE);
}
return session;
}

我不知道我的代码有什么问题。 任何人都可以帮忙吗?

最佳答案

//检查这个。这对你有帮助吗

AndroidAuthSession     session     =     buildSession();
mApi = new DropboxAPI<AndroidAuthSession>(session);
//setLoggedIn(mApi.getSession().isLinked());// I am checking here for its logged in or not

try {
if(session.getAccessTokenPair() !=null){
Log.e("hi","authenticationSuccessful");
//setLoggedIn(true);

Entry dirent1 = mApi.metadata("/", 1000, null, true, null);
}
} catch (DropboxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

关于android - 使用 Dropbox REST 通过 Android 同步您的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8880245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com