使用Tridion UGC Web服务添加评级

时间:2013-02-19 08:23:35

标签: tridion tridion-2011 tridion-content-delivery ugc

我知道我可以通过使用以下内容通过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

约翰

1 个答案:

答案 0 :(得分: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());