从Android删除所有上下文Dialogflow?

时间:2018-02-16 10:15:32

标签: java android retrofit retrofit2 dialogflow

基本网址:https://api.dialogflow.com/v1/

删除' https://api.dialogflow.com/v1/contexts?sessionId=12345'

接头: 授权:持票人YOUR_CLIENT_ACCESS_TOKEN Content-Type:application / json

我正在使用改装2,我想对Dialogflow发出删除请求。我想删除所有上下文。

这是迄今为止所做的:

@DELETE("contexts?sessionId=12345") Call<Void>deletDialogflow(@Header("Content-Type")String content_type, @Header("Authorization")String auth);

在api电话中。

private void deleteContextDialogFlow(){

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(DialogflowService.BASE_URL_DIALOGFLOW)
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    DialogflowService service = retrofit.create(DialogflowService.class);

    Call call = service.deletDialogflow("application/json; charset=utf-8", DialogflowService.BEARER + DialogflowService.TOKEN_DIALOGFLOW);


   call.enqueue(new Callback() {
       @Override
       public void onResponse(Call call, Response response) {

           Log.e("Successful Delete", "" + response.body().toString());

       }

       @Override
       public void onFailure(Call call, Throwable t) {

           Log.e("UnSuccessful Delete", "" + t.getMessage());


       }
   });



}

我没有得到我想要的结果。也就是说,所有情境都会消失。

1 个答案:

答案 0 :(得分:0)

我测试下面的代码工作正常,看看这个。look at this

请仔细查看我的代码:

<强> DialogflowService.java

@Headers("Content-Type:application/json")
@DELETE("contexts?sessionId=12345")
Call<String> deletDialogflow(@Header("Authorization") String auth);

<强> deleteContextDialogFlow()

Call<String> call = service.deletDialogflow(DialogflowService.BEARER+DialogflowService.TOKEN_DIALOGFLOW);
 call.enqueue(new Callback<String>() {
   @Override
   public void onResponse(Call<String> call, Response<String> response) {
      if (response.isSuccessful()) {
        Log.e("Successful Delete", "" + response.body().toString());
        }
        else{
        Log.e("Fail Delete", "" + response.errorBody().string());
        }

   }

   @Override
   public void onFailure(Call<String> call, Throwable t) {
       Log.e("UnSuccessful Delete", "" + t.getMessage());
   }
});