Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UGC post content

I'm just trying to run a little prototype that posts UGC comments using the UGC web service.

The code example is below. I'm getting a 403 response from the web service which indicates I'm not authorised to use the service so I presume I need to create an authentication header? Does anybody have any examples of how to post comments using the UGC web service?

string ugcData = "{d\":{\"Content\":\"FROM WEB SERVICE\",\"Status\":2,\"ItemPublicationId\":\"68\",\"ItemId\":\"17805\",\"ItemType\":\"16\",\"Id\":0,\"ModeratedDate\":\"\",\"LastModifiedDate\":\"\",\"CreationDate\":\"\",\"Score\":0,\"Moderator\":\"\",\"User\":{\"Id\":\"DOMAIN%5Cbsmith\",\"Name\":\"Bill Smith\"}\"}";

WebServiceClient ugcCall = new WebServiceClient();

ugcCall.UploadString("/PostData", "POST", ugcData);

MTIA.

John

like image 884
John Avatar asked Jan 29 '13 10:01

John


People also ask

What is UGC style content?

User-generated content (UGC) refers to any content that is voluntarily created and shared by individuals, fans or consumers of a brand who are not associated with that brand. This could be anything from social media posts to a review on a third-party website. As mentioned, UGC is unbiased and created without an agenda.

Is UGC earned content?

Earned media is also known as user-generated content (UGC) or earned content.

What is an example of user-generated content?

Let's look at 16 UGC examples from brands that get it right: Coca-Cola: Share a Coke Campaign. Doritos: Legion of the Bold. Starbucks: White Cup Contest. Away: UGC Social Media.


2 Answers

You should try to post on the Comments collection:

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

Then you will see that you're missing the CreationDate, moment in which you need to add to your entity something like:

\"CreationDate\":\"/Date(1359457694472)\"

(I have not actually checked if you need more quotes in there). For the format of the date in a JSON string check the odata specs.

If you still have problems, try to change DOMAIN%5Cbsmith to another dummy value ('test' for example).

If that is not enough then maybe you can look at the logs generated by the UGC WebService and try to make-out some stack-trace.

One more thing to notice here: the UGC properties need to be defined correctly in the Web.config in order for the post to even happen.

Hope this helps.

like image 129
Daniel Neagu Avatar answered Oct 09 '22 14:10

Daniel Neagu


I've used the same approach as you are following, namely using a generated proxy for the UGC web service. To create the correct json we used the standard .NET JavaScriptSerializer. This makes the code a bit easier to read, I think.

Here is a code snippet, maybe it helps a bit. Of course you need to make sure the variables are set.

 WSR_ContentDelivery.User user = new WSR_ContentDelivery.User
 {
        Id = GetUserId(),
        Name = username,
        EmailAddress = email,
        ExternalId = website
 };

 WSR_ContentDelivery.Comment comment = new WSR_ContentDelivery.Comment
 {
        CreationDate = DateTime.UtcNow,
        LastModifiedDate = DateTime.UtcNow,
        ItemPublicationId = tcmUri.PublicationId,
        ItemId = tcmUri.ItemId,
        ItemType = tcmUri.ItemTypeId,
        Content = content,
        User = user,
        Status = Statuses.SubmittedNeedsModeration,
        Score = 0
 };

 JavaScriptSerializer serializer = new JavaScriptSerializer();
 return WSClient.UploadString("/Comments", "POST", "{d:" + 
        serializer.Serialize(comment) + "}", user.Id);
like image 28
Quirijn Avatar answered Oct 09 '22 12:10

Quirijn