android 上无法使用 BOX SDK 删除文件

can not delete file using BOX SDK on android

我刚接触 box sdk,我想用它来删除我的 box 文件,但它似乎不起作用。这是我的代码,身份验证工作正常但删除功能有问题:

public class MainActivity extends ActionBarActivity {

private Button button_login;
private Button button_logout;
private Button button_delete;

BoxSession session=null;
BoxApiFile file_delete_api = null;
BoxFile file_delete = null;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    button_login = (Button) findViewById(R.id.button_login);
    button_logout = (Button) findViewById(R.id.button_logout);
    button_delete = (Button) findViewById(R.id.button_delete);


    BoxConfig.CLIENT_ID = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    BoxConfig.CLIENT_SECRET = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";

    BoxConfig.REDIRECT_URL = "http://0.0.0.0";

    session = new BoxSession(MainActivity.this);


    button_login.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           // BoxApiFile fileApi = new BoxApiFile(session);
            session.authenticate();


        }
    });

    button_logout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            session.logout();
        }
    });

    button_delete.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new deletefile().execute();
        }
    });
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

public class deletefile extends AsyncTask<Void,Void,Void>{

    @Override
    protected Void doInBackground(Void... params) {

        file_delete_api = new BoxApiFile(session);
        try {
            file_delete = file_delete_api.getInfoRequest("f_33651677581").send();
           // file_delete = file_delete_api.getUpdateRequest("f_33651677581").setName("change").setDescription("test change").send();
        } catch (BoxException e) {
            e.printStackTrace();
        }


        return null;
    }
}

}

这是日志中的异常:

07-22 21:12:08.582  26066-26287/? W/System.err﹕ at com.box.androidsdk.content.requests.BoxRequest.send(BoxRequest.java:177)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at com.example.kuhou.box_test_delete_file.MainActivity$deletefile.doInBackground(MainActivity.java:102)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at com.example.kuhou.box_test_delete_file.MainActivity$deletefile.doInBackground(MainActivity.java:95)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at android.os.AsyncTask.call(AsyncTask.java:287)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:137)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:230)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at android.os.AsyncTask$SerialExecutor.run(AsyncTask.java:230)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
07-22 21:12:08.582  26066-26287/? W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)

好像有问题
 file_delete = file_delete_api.getInfoRequest("f_33651677581").send();

有没有人可以帮忙?非常感谢。

尝试从文件 ID 中删除前导 f_。该前缀出现在网络中 UI 但 ID 只是数字部分。

file_delete = file_delete_api.getInfoRequest("33651677581").send();

尝试将您正在使用的请求类型更改为删除请求:

    BoxApiFile fileApi = new BoxApiFile(session);
    try {
        fileApi.getDeleteRequest("33651677581").send();
    } catch (BoxException e) {
        e.printStackTrace();
    }