public async void PostOnOwnProfileMethod() { var jsonData = @"{ 'content': { 'contentEntities': [ { 'entityLocation': 'https://www.example.com/content.html', 'thumbnails': [ { 'resolvedUrl': 'https://www.example.com/image.jpg' } ] } ], 'title': 'Test Share with Content' }, 'distribution': { 'linkedInDistributionTarget': {} }, 'subject': 'Test Share Subject from LinkedIn API v2', 'text': { 'text': 'Test Share!' } }"; var share = Share.FromJson(jsonData); //var contentEntity = new ContentEntity(); //contentEntity.EntityLocation = new Uri("https://www.example.com/content.html"); //contentEntity.Thumbnails.Add(new ShareThumbnails() { ResolvedUrl = new Uri("http://suxrobgm.net/Blogs/Introducing-NET-5") }); //var share = new Share(); //share.Content.ContentEntities.Add(contentEntity); //share.Content.Title = "Test Share with Content"; //share.Subject = "Test Share Subject"; //share.Text.Content = "Test Share!"; var postedShare = await client.PostOnOwnProfileAsync(share); var postedShareJson = postedShare.ToJson(); Assert.Contains("id", postedShareJson); Assert.Contains("created", postedShareJson); Assert.Contains("edited", postedShareJson); Assert.Contains("linkedInDistributionTarget", postedShareJson); Assert.Contains("lastModified", postedShareJson); Assert.Contains("owner", postedShareJson); Assert.Contains("subject", postedShareJson); Assert.Contains("text", postedShareJson); }
private async Task <Share> PostShareAsync(Share share) { CheckTokenThenAddToHeaders(); var content = new StringContent(share.ToJson(), Encoding.UTF8, "application/json"); var response = await _client.PostAsync($"{_apiHost}v2/shares", content); var responseJson = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { throw new ApiException(ExceptionModel.FromJson(responseJson)); } return(Share.FromJson(responseJson)); }