2012-01-16 14 views
1

私のリストをdropbox REST APIと同期させたいのですが。 これをどのように達成できますか?ボタンをクリックして 私は内容をアップロードしています。 しかし、私はここにDropboxUnlinkedExceptionあなたはDropbox RESTを使ってアンドロイドでリストを同期します。

を取得していますがいただきました!私のコードで間違って、私は知らない私のコード

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; 
     } 

です。 誰でも助けてくれますか?

+0

あなたのエラーログを投稿してください。 –

答えて

1

//これをチェックアウトする。あなたはあなたがアクセストークンとアクセス秘密でMAPIを装備され、次のように行われた最初の認証を受ける必要があります

mApi.putFile("/testing.txt", inputStream, 
    fileContents.length(), null, null) 

を使用する前に、これはあなた

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(); 
     } 
0

のために有用です。

あなたはMAPIを使用するのは自由です。この後
bAuth.setOnClickListener(new OnClickListener() { 
    @Override 
     public void onClick(View v) { 
     // This logs you out if you're logged in, or vice versa 
     if (mLoggedIn) { 
      logOut(); 
     } else { 
      // Start the remote authentication 
      mApi.getSession().startAuthentication(MCActivity.this);//this directs you to your browser for authentication 
     } 
    } 
}); 

..

関連する問題