/// <summary> /// FOR VIDEO. /// </summary> /// <param name="token"></param> /// <param name="account"></param> /// <param name="videoPath"></param> /// <param name="description"></param> /// <returns></returns> public LinkedInAPIResult <bool> SharePost(OAuthv2AccessToken token, LinkedInAccount account, string videoPath, string description) { try { var registerUploadResponse = RegisterVideoUpload(token, LinkedInRegisterUploadRequest.Create(account.UserId, account.PersonalOrOrganization)); if (!registerUploadResponse.IsSuccessful) { return(LinkedInAPIResult <bool> .Fail("An error has occured while trying to register video upload on LinkedIn. Details: " + registerUploadResponse.Message)); } var uploadResponse = UploadVideo(token, videoPath, registerUploadResponse.Entity.Value.UploadMechanism.ComLinkedinDigitalmediaUploadingMediaUploadHttpRequest.UploadUrl); if (!uploadResponse.IsSuccessful) { return(LinkedInAPIResult <bool> .Fail("An error has occured while trying to upload video on LinkedIn. Details: " + uploadResponse.Message)); } var createUgcPostResponse = CreateOrganicUGCPost(token, RequestCreateUGCPost.Create(account, registerUploadResponse.Entity.Value.Asset, description)); if (!createUgcPostResponse.IsSuccessful) { return(LinkedInAPIResult <bool> .Fail("An error has occured while trying to creating organic UGC post with video on LinkedIn. Details: " + createUgcPostResponse.Message)); } return(LinkedInAPIResult <bool> .Success(true)); } catch (Exception ex) { return(LinkedInAPIResult <bool> .Fail("An error has occured while trying publish post with video on LinkedIn. Details: " + ex.Message)); } }
/// <summary> /// 400 urn:li:developerApplication:{developer application ID} does not have permission to create ugc posts /// Indicates your developer application is not allowlisted to create video UGC Posts. /// UGC Post video creation is restricted to approved applications only. /// </summary> /// <param name="token"></param> /// <param name="createUgcPostRequest"></param> /// <returns></returns> public LinkedInAPIResult <bool> CreateOrganicUGCPost(OAuthv2AccessToken token, RequestCreateUGCPost createUgcPostRequest) { var _linkedInRestClient = new RestClient("https://api.linkedin.com/v2/ugcPosts") { Authenticator = new JwtAuthenticator(token.AccessToken) }; var request = new RestRequest(Method.POST); request.AddJsonBody(createUgcPostRequest.ToJson()); try { var response = _linkedInRestClient.Execute(request); if (!response.IsSuccessful) { return(LinkedInAPIResult <bool> .Fail(response.Content)); } return(LinkedInAPIResult <bool> .Success(true)); } catch (Exception ex) { return(LinkedInAPIResult <bool> .Fail(ex.Message)); } }