Question

I try to call a share REST API with Hammock library function in my MVC 4 application.

Please see my code below

    public ActionResult SharePost()
    {
        string content = "";
        try
        {
            var credentials = new OAuthCredentials
            {
                ConsumerKey = "xxxxxxxxxxxxxx",
                ConsumerSecret = "xxxxxxxxxxxxxxxx",
                Token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
                TokenSecret = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
                Verifier = verifier,
                Type = OAuthType.AccessToken,
                ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
                SignatureMethod = OAuthSignatureMethod.HmacSha1,
                Version = "1.0"
            };

            var client = new RestClient { Authority = "http://api.linkedin.com/v1", Credentials = credentials, Method = WebMethod.Post };
            var request = new RestRequest { Path = "/people/~/shares" };

            StringBuilder sbAppend = new StringBuilder();
            sbAppend.AppendLine("<?xml version=1.0 encoding=UTF-8?>");
            sbAppend.AppendLine("<share><comment>Check out the LinkedIn Share API!</comment><content><title>LinkedIn Developers Documentation On Using the Share API</title><description>Leverage the Share API to maximize engagement on user-generated content on LinkedIn</description><submitted-url>https://developer.linkedin.com/documents/share-api</submitted-url><submitted-image-url>http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png</submitted-image-url></content><visibility><code>anyone</code></visibility></share>");

            client.AddHeader("Content-Type", "text/xml");

            byte[] msg = Encoding.Default.GetBytes(sbAppend.ToString());
            client.AddPostContent(msg);

            RestResponse response = client.Request(request);
            content = response.Content;

        }
        catch (Exception ex)
        {
            throw ex;
        }
        return Content(content);
    }

But i get a error responce.content

enter image description here

Edit

I use double quotes in my xml header. but always shows the same error.

enter image description here

Is there any thing wrong.

I didn't see the post xml values in fiddller. Please see this image

enter image description here

Please help.

Was it helpful?

Solution

I found error in your XML you are missing "" Try this

sbAppend.AppendLine('<?xml version="1.0" encoding="UTF-8"?>');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top