我在dropbox网站上学习这个教程。
我已经获得了应用程序的密钥和秘密,并将它们放在我的代码中,并在清单中的正确位置。此外,舱单也有互联网许可。
所以布景没问题。该应用程序的目的是上传一个文本文件到我的dropbox帐户。它似乎开始正确地进行身份验证,但是putFile()方法正在抛出一个DropboxUnlinkedException。当应用程序运行时,您必须允许访问您在电话上的帐户,当我单击“允许”应用程序完成正确的身份验证时。我认为,除了执行putfile()方法之外,一切都很好。
我试过在应用程序开始时清除键,但仍然没有运气。
我做了一些日志,但不知道现在该做什么,有什么想法吗?
谢谢马特。
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import com.dropbox.client2.DropboxAPI;
import com.dropbox.client2.DropboxAPI.Entry;
import com.dropbox.client2.android.AndroidAuthSession;
import com.dropbox.client2.exception.DropboxException;
import com.dropbox.client2.exception.DropboxUnlinkedException;
import com.dropbox.client2.session.AccessTokenPair;
import com.dropbox.client2.session.AppKeyPair;
import com.dropbox.client2.session.Session.AccessType;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
public class DropboxfileuploadActivity extends Activity {
private static final String TAG = "DropboxfileuploadActivity";
final static private String APP_KEY = "***********";
final static private String APP_SECRET = "k3i***********";
final static private AccessType ACCESS_TYPE = AccessType.APP_FOLDER;
final static private String ACCOUNT_PREFS_NAME = "prefs";
final static private String ACCESS_KEY_NAME = "ACCESS_KEY";
final static private String ACCESS_SECRET_NAME = "ACCESS_SECRET";
private DropboxAPI<AndroidAuthSession> mDBApi;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
clearKeys();
Log.e(TAG, "keys cleared");
AppKeyPair appKeys = new AppKeyPair(APP_KEY, APP_SECRET);
AndroidAuthSession session = new AndroidAuthSession(appKeys, ACCESS_TYPE);
mDBApi = new DropboxAPI<AndroidAuthSession>(session);
mDBApi.getSession().startAuthentication(DropboxfileuploadActivity.this);
Log.e(TAG, "started authentication");
FileInputStream inputStream = null;
try {
File fileToUpload = new File(Environment.getExternalStorageDirectory()
+File.separator
+"dropboxapp");
fileToUpload.mkdirs();
Log.e(TAG, "dirs made");
File file = new File(fileToUpload.getAbsolutePath()+"/uploadedFile.txt");
Log.e(TAG, "the file to be uploaded has a size of "+file.length()+" bytes");
inputStream = new FileInputStream(file);
Log.e(TAG, "inputstream created");
Entry newEntry = mDBApi.putFile("/test.txt", inputStream,
file.length(), null, null);
Log.e(TAG, "putFile method executed");
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.");
} catch (FileNotFoundException e) {
Log.e("DbExampleLog", "File not found.");
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {}
}
}
setContentView(R.layout.main);
}//end of oncreate()
protected void onResume() {
super.onResume();
if (mDBApi.getSession().authenticationSuccessful()) {
try {
// MANDATORY call to complete auth.
// Sets the access token on the session
mDBApi.getSession().finishAuthentication();
if(mDBApi.getSession().authenticationSuccessful()){
Log.e(TAG, "Authentication finished");
}
AccessTokenPair tokens = mDBApi.getSession().getAccessTokenPair();
// Provide your own storeKeys to persist the access token pair
// A typical way to store tokens is using SharedPreferences
storeKeys(tokens.key, tokens.secret);
} catch (IllegalStateException e) {
Log.i("DbAuthLog", "Error authenticating", e);
}
}
}//end of onResume()
private void storeKeys(String key, String secret) {
// Save the access key for later
SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS_NAME, 0);
Editor edit = prefs.edit();
edit.putString(ACCESS_KEY_NAME, key);
edit.putString(ACCESS_SECRET_NAME, secret);
edit.commit();
}
private void clearKeys() {
SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS_NAME, 0);
Editor edit = prefs.edit();
edit.clear();
edit.commit();
}
}//end of class。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tecmark.dropboxfileupload"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="3" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".DropboxfileuploadActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.dropbox.client2.android.AuthActivity"
android:launchMode="singleTask"
android:configChanges="orientation|keyboard">
<intent-filter>
<!-- Change this to be db- followed by your app key -->
<data android:scheme="db-3*********" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
</manifest>。
06-03 09:54:51.117: E/DropboxfileuploadActivity(20365): started authentication
06-03 09:54:51.117: E/DropboxfileuploadActivity(20365): dirs made
06-03 09:54:51.117: E/DropboxfileuploadActivity(20365): the file to be uploaded has a size of 147 bytes
06-03 09:54:51.117: E/DropboxfileuploadActivity(20365): inputstream created
06-03 09:54:51.117: E/DbExampleLog(20365): User has unlinked.
06-03 09:54:57.397: E/DropboxfileuploadActivity(20365): Authentication finished。
这是完整的一叠。
06-03 09:54:51.067: E/DropboxfileuploadActivity(20365): keys cleared
06-03 09:54:51.077: E/dalvikvm(20365): Could not find class 'org.json.simple.JSONArray', referenced from method com.dropbox.client2.DropboxAPI.revisions
06-03 09:54:51.077: W/dalvikvm(20365): VFY: unable to resolve check-cast 223 (Lorg/json/simple/JSONArray;) in Lcom/dropbox/client2/DropboxAPI;
06-03 09:54:51.087: D/dalvikvm(20365): VFY: replacing opcode 0x1f at 0x0053
06-03 09:54:51.087: E/dalvikvm(20365): Could not find class 'org.json.simple.JSONArray', referenced from method com.dropbox.client2.DropboxAPI.search
06-03 09:54:51.087: W/dalvikvm(20365): VFY: unable to resolve instanceof 223 (Lorg/json/simple/JSONArray;) in Lcom/dropbox/client2/DropboxAPI;
06-03 09:54:51.087: D/dalvikvm(20365): VFY: replacing opcode 0x20 at 0x006d
06-03 09:54:51.117: E/DropboxfileuploadActivity(20365): started authentication
06-03 09:54:51.117: E/DropboxfileuploadActivity(20365): dirs made
06-03 09:54:51.117: E/DropboxfileuploadActivity(20365): the file to be uploaded has a size of 147 bytes
06-03 09:54:51.117: E/DropboxfileuploadActivity(20365): inputstream created
06-03 09:54:51.117: E/DbExampleLog(20365): User has unlinked.
06-03 09:54:57.397: E/DropboxfileuploadActivity(20365): Authentication finished
06-03 10:21:31.087: W/IInputConnectionWrapper(20365): showStatusIcon on inactive InputConnection
06-03 10:21:31.087: W/IInputConnectionWrapper(20365): InputConnection = android.view.inputmethod.BaseInputConnection@40d727e0, active client = false发布于 2013-02-08 07:23:43
我已经解决了这个问题。
由于你还没有在这里贴出答案,我想这个问题对你仍然是开放的。
遵循以下步骤:(我只会提到我所遵循的额外步骤)
json_simple-1.1.jar (将出现右复选标记)json_simple-1.1.jar和dropbox-android-sdk jar,然后按下右边的向上按钮,将它们移动UP。它已经完成了:)
https://stackoverflow.com/questions/10869145
复制相似问题