如何更新Contentful中的条目

时间:2017-10-23 12:47:11

标签: android contentful

我没有更新我的条目,在我尝试更新之前,我使用client.entries().async().unPublish(entry)取消发布条目,并且它有效,但是当我尝试使用下面的代码进行更新时,我收到以下消息: java.lang.IllegalArgumentException: entry must have a space associated.

我做错了什么?

 final CMAClient client =
                        new CMAClient
                                .Builder()
                                .setAccessToken(contentfulConnection.getCMA_TOKEN())
                                .build();
     final CMASystem sys = new CMASystem();

    sys.setId(entryID).setVersion(CurrentVersion);  

    CMAEntry entry;
    entry.setField("name", "en-US", "TEST").setSystem(sys); 
    entry.setSpaceId(SPACE_ID);
    entry.setID("entryID");     


    client.entries().async().update(entry, new CMACallback<CMAEntry>() {

                @Override protected void onSuccess(CMAEntry entry) {

                   // Successfully created a new entry.

                   new AlertDialog.Builder(ctx).setTitle("Contentful")                                                                                                                                                                                 
                   .setMessage("Creation of an entry was successful." +"\n\nResult: 
                   " + 
                   entry).show();                                                                                                                                                                                           
    }           }


@Override protected void onFailure(RuntimeException exception) {

    // An error occurred! Inform the user.

    new AlertDialog.Builder(ctx)

    .setTitle("Contentful Error")

    .setMessage("Could not create an entry." +

   "\n\nReason: " + exception.toString())



       .show();

       System.out.println(exception.toString());


       super.onFailure(exception);
                                                                                    }
                                                                                }
                                                                        );

1 个答案:

答案 0 :(得分:0)

我是Contentful Java SDK的维护者。

使用update方法的推荐方法是首先获取项目,更改其数据然后再次更新。

如果您点击此链接to our documentation,然后选择create/update an entry按钮,则会看到有关如何更新条目的代码段。请选择Android平台以查看Android版本。

我希望这会对你有所帮助。