3

我知道我可以通过 UGC 网络服务添加评论,方法如下:-

WebServiceClient ugcCall = new WebServiceClient();

string ugcData = "{ \"d\" :{\"Content\":\"" + comment + "\",\"Status\":2,\"ItemPublicationId\":\"" + PublicationId + "\",\"ItemId\":\"" + itemid + "\",\"ItemType\":\"16\",\"Id\":0,\"ModeratedDate\":\"\",\"LastModifiedDate\":\"\",\"CreationDate\":\"\",\"Score\":0,\"Moderator\":\"\",\"User\":{\"Id\":\"ACME%5Cjbloggs\",\"Name\":\"Joe Bloggs\"}}}";

string result = ugcCall.UploadString("/Comments", "POST", ugcData);

我的问题是添加评级和好恶的语法是什么?这在任何地方都有记录吗?

MTIA

约翰

4

1 回答 1

5

上传评分的命令是“/Ratings”而不是“/Comments”。当然,JSON 也不同。在下面的代码中,我没有手动写出 JSON,而是构造了一个简单的 Rating 对象并使用 JavascriptSerializer 将其转换为 JSON:

TcmUri tcmUri = new TcmUri(itemUri);
WSR_ContentDelivery.User user = new WSR_ContentDelivery.User { Id = GetUserId() };
WSR_ContentDelivery.Rating rating = new WSR_ContentDelivery.Rating
{
  CreationDate = DateTime.UtcNow,
  LastModifiedDate = DateTime.UtcNow,
  ItemPublicationId = tcmUri.PublicationId,
  ItemId = tcmUri.ItemId,
  ItemType = tcmUri.ItemTypeId,
  RatingValue = ratingValue.ToString(),
  User = user,
  Id = "0"
};

JavaScriptSerializer oSerializer = new JavaScriptSerializer();

WSClient.UploadString("/Ratings", "POST", "{d:" + oSerializer.Serialize(rating) + "}", GetUserId());
于 2013-02-19T13:13:29.790 回答