Beispiel #1
0
        private async Task PublishTest(UserAuthorization user)
        {
            //// var getVideo = await this.api.Asset.GetAssetAsync(user, "C4D05AQH5Hen4KpIFqA");


            //// var videoData = DownladFromUrlToByte("https://c3labsdevstorage.blob.core.windows.net/7e46a98d-a143-4a4d-8e05-b3f95493cce4/e21b6488-8d6e-43e6-8c88-4ac4438ff8cb/videos/48c2071e-e9b0-43f7-8b8a-01da4d8c04a1.mp4");
            //var videoData1 = DownladFromUrlToByte("https://c3labsdevstorage.blob.core.windows.net/7e46a98d-a143-4a4d-8e05-b3f95493cce4/e21b6488-8d6e-43e6-8c88-4ac4438ff8cb/videos/f57f8bc8-4fc8-44e4-9c5f-40f528f1a295.mp4");

            //// var bigVideo = DownladFromUrlToByte("https://c3labsdevstorage.blob.core.windows.net/edf54915-d374-4074-a8ee-196897a7badd/07569e4a-134f-48ec-96cf-c89dd1234e9b/videos/152d90cb-3501-4673-a5b2-1ff61ecc9d33.mpeg");


            //var aaa = await Video.VideoUpload.UploadVideoAsync(api, user, "urn:li:organization:18568129", videoData1);
            //var bb = "";



            //// Asset test
            //var asset = new Asset.RegisterUploadRequest()
            //{
            //    RegisterUploadRequestData = new Asset.RegisterUploadRequestData()
            //    {

            //        // fileSizeIn bytes
            //        FileSize = 52429800,
            //        SupportedUploadMechanism = new List<string>() { "MULTIPART_UPLOAD" },
            //        // SupportedUploadMechanism = new List<string>() { "SINGLE_REQUEST_UPLOAD" },
            //        // Owner = "urn:li:person:" + "qhwvZ0K4cr",
            //        Owner = "urn:li:organization:18568129",
            //        Recipes = new List<string>() { "urn:li:digitalmediaRecipe:feedshare-video" },
            //        ServiceRelationships = new List<Asset.ServiceRelationship>()
            //        {
            //            new Asset.ServiceRelationship()
            //            {
            //                Identifier = "urn:li:userGeneratedContent",
            //                RelationshipType = "OWNER"
            //            }
            //        }
            //    }
            //};
            //var requestAsset = await this.api.Asset.RegisterUploadAsync(user, asset);


            //var multiPartSend = await Internals.LongVideoUpload.UploadLongVideoPartsAsync(this.api, requestAsset, bigVideo);

            ////var postAsset = await this.api.Asset.UploadAssetAsync(requestAsset.Value.UploadMechanism.ComLinkedinDigitalmediaUploadingMediaUploadHttpRequest.UploadUrl, new Asset.UploadAssetRequest()
            ////{
            ////    RequestHeaders = new Asset.ComLinkedinDigitalmediaUploadingMediaUploadHttpRequest()
            ////    {
            ////        Headers = requestAsset.Value.UploadMechanism.ComLinkedinDigitalmediaUploadingMediaUploadHttpRequest.Headers,
            ////        UploadUrl = requestAsset.Value.UploadMechanism.ComLinkedinDigitalmediaUploadingMediaUploadHttpRequest.UploadUrl,
            ////    },
            ////    Data = videoData1
            ////});

            //var test = "sss";



            // video test
            var ugcPost = new UGCPost.UGCPostData()
            {
                // Author = "urn:li:person:" + "qhwvZ0K4cr",
                // Author = "urn:li:organization:" + "18568129",
                Author          = "urn:li:organization:18568129",
                LifecycleState  = "PUBLISHED",
                SpecificContent = new UGCPost.SpecificContent()
                {
                    ComLinkedinUgcShareContent = new UGCPost.ComLinkedinUgcShareContent()
                    {
                        UGCMedia = new List <UGCPost.UGCMedia>()
                        {
                            new UGCPost.UGCMedia()
                            {
                                UGCMediaDescription = new UGCPost.UGCText()
                                {
                                    Text = "test description"
                                },
                                Media  = "urn:li:digitalmediaAsset:C4D05AQGYz5sONvv20g",       // requestAsset.Value.Asset, // "urn:li:digitalmediaAsset:C4D05AQHwsp8DLpxHiA", // "urn:li:digitalmediaAsset:C5500AQG7r2u00ByWjw",
                                Status = "READY",
                                // Thumbnails = new List<string>(),
                                UGCMediaTitle = new UGCPost.UGCText()
                                {
                                    Text = "Test Title"
                                }
                            }
                        },
                        ShareCommentary = new UGCPost.UGCText()
                        {
                            Text = "Test Commentary"
                        },
                        ShareMediaCategory = "VIDEO"
                    }
                },
                //TargetAudience = new Common.TargetAudience()
                //{

                //},
                Visibility = new UGCPost.UGCPostvisibility()
                {
                    comLinkedinUgcMemberNetworkVisibility = "PUBLIC"
                }
            };

            var ugcPostResult = await this.api.UGCPost.PostAsync(user, ugcPost);

            var test2 = "sdfas";



            //// image test
            //// var imageData = DownladFromUrlToByte("https://c3labsdevstorage.blob.core.windows.net/7e46a98d-a143-4a4d-8e05-b3f95493cce4/e21b6488-8d6e-43e6-8c88-4ac4438ff8cb/images/83278b25-b809-4458-912b-55b4d6d8b19d.jpg");
            //var imageData = DownladFromUrlToByte("https://c3labsdevstorage.blob.core.windows.net/7e46a98d-a143-4a4d-8e05-b3f95493cce4/e21b6488-8d6e-43e6-8c88-4ac4438ff8cb/images/b7b12f6e-4eed-4ca1-b937-006b0c2aa93b.jpg");

            //var postId = this.api.Media.Post(user, new Common.MediaUploadData()
            //{
            //    Data = imageData
            //});

            //var test = "sdfas";



            // var profile1 =  this.api.Profiles.GetMyProfile(user, acceptLanguages, fields);


            //var firstName = profile.FirstName.Localized.First.ToObject<string>();
            //var firstName1 = profile.FirstName.Localized.First.Last.ToString();
            //var firstName2 = profile.FirstName.Localized.First.ToObject<string>();

            //var fieldsOrg = FieldSelector.For<OrganizationalEntityAcls>()
            //    .WithAllFields();
            //var userCompanies = this.api.Organizations.GetUserAdminApprOrganizations(user, fieldsOrg);


            //var statistic = this.api.Shares.GetShareStatistics(user, "18568129", "6386953337324994560");

            //var orgFollorerStatistic = this.api.Organizations.GetOrgFollowerStatistics(user, "18568129");

            //var getShares = this.api.Shares.GetShares(user, "urn:li:organization:18568129", 1000, 5, 0);

            //var postResult = this.api.Shares.Post(user, new Common.PostShare()
            //{
            //    Content = new Common.PostShareContent()
            //    {
            //        Title = "tttt",
            //        ContentEntities = new List<Common.PostShareContentEntities>() { new Common.PostShareContentEntities() {
            //                  //EntityLocation = "https://www.example.com/",
            //                  //Thumbnails = new List<Common.PostShareContentThumbnails>(){new Common.PostShareContentThumbnails()
            //                  //{
            //                  //    ResolvedUrl = "http://wac.2f9ad.chicdn.net/802F9AD/u/joyent.wme/public/wme/assets/ec050984-7b81-11e6-96e0-8905cd656caf.jpg?v=30"
            //                  //} }
            //                  Entity = postId.Location
            //              }
            //          }
            //    },
            //    Distribution = new Common.Distribution()
            //    {
            //        LinkedInDistributionTarget = new Common.LinkedInDistributionTarget()
            //        {
            //            VisibleToGuest = true
            //        }
            //    },
            //    Subject = "sub",
            //    Text = new Common.PostShareText()
            //    {
            //        Text = "text"
            //    },
            //    // Owner = "urn:li:person:" + "123456789"
            //    Owner = "urn:li:organization:18568129",
            //}
            //);
        }
        private async Task <string> Publish_Video_Ugc(UserAuthorization user, string ownerUrn, string mediaUrl)
        {
            try
            {
                var videoData = DownladFromUrlToByte(mediaUrl);
                var video     = await Video.VideoUpload.UploadVideoAsync(api, user, ownerUrn, videoData);

                //video test
                var ugcPost = new UGCPost.UGCPostData()
                {
                    Author         = ownerUrn,
                    LifecycleState = "PUBLISHED",

                    SpecificContent = new UGCPost.SpecificContent()
                    {
                        ComLinkedinUgcShareContent = new UGCPost.ComLinkedinUgcShareContent()
                        {
                            UGCMedia = new List <UGCPost.UGCMedia>()
                            {
                                new UGCPost.UGCMedia()
                                {
                                    UGCMediaDescription = new UGCPost.UGCText()
                                    {
                                        Text = "Description"
                                    },
                                    Media      = video,
                                    Status     = "READY",
                                    Thumbnails = new List <ImageThumbnail>()
                                    {
                                        new ImageThumbnail()
                                        {
                                            Url    = "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png",
                                            Height = 500,
                                            Width  = 300
                                        }
                                    },
                                    UGCMediaTitle = new UGCPost.UGCText()
                                    {
                                        Text = "Title"
                                    }
                                }
                            },
                            ShareCommentary = new UGCPost.UGCText()
                            {
                                Text = "New video with Thumbnails 2"
                            },
                            ShareMediaCategory = "VIDEO"
                        }
                    },
                    Visibility = new UGCPost.UGCPostvisibility()
                    {
                        comLinkedinUgcMemberNetworkVisibility = "PUBLIC"
                    }
                };

                var t = JsonConvert.SerializeObject(ugcPost);

                var ugcPostResult = await api.UGCPost.PostAsync(user, ugcPost);

                return(ugcPostResult);
            }
            catch (LinkedInApiException ex)
            {
                errors.Add(ex.ToString());
                return(null);
            }
            catch (Exception ex)
            {
                errors.Add(ex.ToString());
                return(null);
            }
        }
Beispiel #3
0
        public async Task <ActionResult> Index(string culture = "en-US")
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            // step 1: configuration
            this.ViewBag.Configuration = this.apiConfig;

            // step 2: authorize url
            var scope       = AuthorizationScope.ReadEmailAddress | AuthorizationScope.ReadWriteCompanyPage | AuthorizationScope.WriteShare;
            var state       = Guid.NewGuid().ToString();
            var redirectUrl = this.Request.Compose() + this.Url.Action("OAuth2");

            this.ViewBag.LocalRedirectUrl = redirectUrl;
            if (this.apiConfig != null && !string.IsNullOrEmpty(this.apiConfig.ApiKey))
            {
                var authorizeUrl = this.api.OAuth2.GetAuthorizationUrl(scope, state, redirectUrl);
                this.ViewBag.Url = authorizeUrl;
            }
            else
            {
                this.ViewBag.Url = null;
            }

            var accessToken = "";

            this.data.SaveAccessToken(accessToken);


            // step 3
            if (this.data.HasAccessToken)
            {
                var token = this.data.GetAccessToken();
                this.ViewBag.Token = token;
                var user = new UserAuthorization(token);

                var watch = new Stopwatch();
                watch.Start();
                try
                {
                    ////var profile = this.api.Profiles.GetMyProfile(user);
                    var acceptLanguages = new string[] { culture ?? "en-US", "fr-FR", };
                    var fields          = FieldSelector.For <Person>()
                                          .WithAllFields();
                    var profile = await this.api.Profiles.GetMyProfileAsync(user, acceptLanguages, fields);


                    // var getVideo = await this.api.Asset.GetAssetAsync(user, "C4D05AQH5Hen4KpIFqA");


                    // var videoData = DownladFromUrlToByte("https://c3labsdevstorage.blob.core.windows.net/7e46a98d-a143-4a4d-8e05-b3f95493cce4/e21b6488-8d6e-43e6-8c88-4ac4438ff8cb/videos/48c2071e-e9b0-43f7-8b8a-01da4d8c04a1.mp4");
                    var videoData1 = DownladFromUrlToByte("https://c3labsdevstorage.blob.core.windows.net/7e46a98d-a143-4a4d-8e05-b3f95493cce4/e21b6488-8d6e-43e6-8c88-4ac4438ff8cb/videos/f57f8bc8-4fc8-44e4-9c5f-40f528f1a295.mp4");

                    // var bigVideo = DownladFromUrlToByte("https://c3labsdevstorage.blob.core.windows.net/edf54915-d374-4074-a8ee-196897a7badd/07569e4a-134f-48ec-96cf-c89dd1234e9b/videos/152d90cb-3501-4673-a5b2-1ff61ecc9d33.mpeg");


                    var aaa = await Video.VideoUpload.UploadVideoAsync(api, user, "urn:li:organization:18568129", videoData1);

                    var bb = "";



                    //// Asset test
                    //var asset = new Asset.RegisterUploadRequest()
                    //{
                    //    RegisterUploadRequestData = new Asset.RegisterUploadRequestData()
                    //    {

                    //        // fileSizeIn bytes
                    //        FileSize = 52429800,
                    //        SupportedUploadMechanism = new List<string>() { "MULTIPART_UPLOAD" },
                    //        // SupportedUploadMechanism = new List<string>() { "SINGLE_REQUEST_UPLOAD" },
                    //        // Owner = "urn:li:person:" + "qhwvZ0K4cr",
                    //        Owner = "urn:li:organization:18568129",
                    //        Recipes = new List<string>() { "urn:li:digitalmediaRecipe:feedshare-video" },
                    //        ServiceRelationships = new List<Asset.ServiceRelationship>()
                    //        {
                    //            new Asset.ServiceRelationship()
                    //            {
                    //                Identifier = "urn:li:userGeneratedContent",
                    //                RelationshipType = "OWNER"
                    //            }
                    //        }
                    //    }
                    //};
                    //var requestAsset = await this.api.Asset.RegisterUploadAsync(user, asset);


                    //var multiPartSend = await Internals.LongVideoUpload.UploadLongVideoPartsAsync(this.api, requestAsset, bigVideo);

                    ////var postAsset = await this.api.Asset.UploadAssetAsync(requestAsset.Value.UploadMechanism.ComLinkedinDigitalmediaUploadingMediaUploadHttpRequest.UploadUrl, new Asset.UploadAssetRequest()
                    ////{
                    ////    RequestHeaders = new Asset.ComLinkedinDigitalmediaUploadingMediaUploadHttpRequest()
                    ////    {
                    ////        Headers = requestAsset.Value.UploadMechanism.ComLinkedinDigitalmediaUploadingMediaUploadHttpRequest.Headers,
                    ////        UploadUrl = requestAsset.Value.UploadMechanism.ComLinkedinDigitalmediaUploadingMediaUploadHttpRequest.UploadUrl,
                    ////    },
                    ////    Data = videoData1
                    ////});

                    //var test = "sss";



                    // video test
                    var ugcPost = new UGCPost.UGCPostData()
                    {
                        // Author = "urn:li:person:" + "qhwvZ0K4cr",
                        // Author = "urn:li:organization:" + "18568129",
                        Author          = "urn:li:organization:18568129",
                        LifecycleState  = "PUBLISHED",
                        SpecificContent = new UGCPost.SpecificContent()
                        {
                            ComLinkedinUgcShareContent = new UGCPost.ComLinkedinUgcShareContent()
                            {
                                UGCMedia = new List <UGCPost.UGCMedia>()
                                {
                                    new UGCPost.UGCMedia()
                                    {
                                        UGCMediaDescription = new UGCPost.UGCText()
                                        {
                                            Text = "test description"
                                        },
                                        Media  = "urn:li:digitalmediaAsset:C4D05AQGYz5sONvv20g",// requestAsset.Value.Asset, // "urn:li:digitalmediaAsset:C4D05AQHwsp8DLpxHiA", // "urn:li:digitalmediaAsset:C5500AQG7r2u00ByWjw",
                                        Status = "READY",
                                        // Thumbnails = new List<string>(),
                                        UGCMediaTitle = new UGCPost.UGCText()
                                        {
                                            Text = "Test Title"
                                        }
                                    }
                                },
                                ShareCommentary = new UGCPost.UGCText()
                                {
                                    Text = "Test Commentary"
                                },
                                ShareMediaCategory = "VIDEO"
                            }
                        },
                        //TargetAudience = new Common.TargetAudience()
                        //{

                        //},
                        Visibility = new UGCPost.UGCPostvisibility()
                        {
                            comLinkedinUgcMemberNetworkVisibility = "PUBLIC"
                        }
                    };

                    var ugcPostResult = await this.api.UGCPost.PostAsync(user, ugcPost);

                    var test2 = "sdfas";



                    //// image test
                    //// var imageData = DownladFromUrlToByte("https://c3labsdevstorage.blob.core.windows.net/7e46a98d-a143-4a4d-8e05-b3f95493cce4/e21b6488-8d6e-43e6-8c88-4ac4438ff8cb/images/83278b25-b809-4458-912b-55b4d6d8b19d.jpg");
                    //var imageData = DownladFromUrlToByte("https://c3labsdevstorage.blob.core.windows.net/7e46a98d-a143-4a4d-8e05-b3f95493cce4/e21b6488-8d6e-43e6-8c88-4ac4438ff8cb/images/b7b12f6e-4eed-4ca1-b937-006b0c2aa93b.jpg");

                    //var postId = this.api.Media.Post(user, new Common.MediaUploadData()
                    //{
                    //    Data = imageData
                    //});

                    //var test = "sdfas";



                    // var profile1 =  this.api.Profiles.GetMyProfile(user, acceptLanguages, fields);


                    //var firstName = profile.FirstName.Localized.First.ToObject<string>();
                    //var firstName1 = profile.FirstName.Localized.First.Last.ToString();
                    //var firstName2 = profile.FirstName.Localized.First.ToObject<string>();

                    //var fieldsOrg = FieldSelector.For<OrganizationalEntityAcls>()
                    //    .WithAllFields();
                    //var userCompanies = this.api.Organizations.GetUserAdminApprOrganizations(user, fieldsOrg);


                    //var statistic = this.api.Shares.GetShareStatistics(user, "18568129", "6386953337324994560");

                    //var orgFollorerStatistic = this.api.Organizations.GetOrgFollowerStatistics(user, "18568129");

                    //var getShares = this.api.Shares.GetShares(user, "urn:li:organization:18568129", 1000, 5, 0);

                    //var postResult = this.api.Shares.Post(user, new Common.PostShare()
                    //{
                    //    Content = new Common.PostShareContent()
                    //    {
                    //        Title = "tttt",
                    //        ContentEntities = new List<Common.PostShareContentEntities>() { new Common.PostShareContentEntities() {
                    //                  //EntityLocation = "https://www.example.com/",
                    //                  //Thumbnails = new List<Common.PostShareContentThumbnails>(){new Common.PostShareContentThumbnails()
                    //                  //{
                    //                  //    ResolvedUrl = "http://wac.2f9ad.chicdn.net/802F9AD/u/joyent.wme/public/wme/assets/ec050984-7b81-11e6-96e0-8905cd656caf.jpg?v=30"
                    //                  //} }
                    //                  Entity = postId.Location
                    //              }
                    //          }
                    //    },
                    //    Distribution = new Common.Distribution()
                    //    {
                    //        LinkedInDistributionTarget = new Common.LinkedInDistributionTarget()
                    //        {
                    //            VisibleToGuest = true
                    //        }
                    //    },
                    //    Subject = "sub",
                    //    Text = new Common.PostShareText()
                    //    {
                    //        Text = "text"
                    //    },
                    //    // Owner = "urn:li:person:" + "123456789"
                    //    Owner = "urn:li:organization:18568129",
                    //}
                    //);

                    // var originalPicture = await this.api.Profiles.GetOriginalProfilePictureAsync(user);
                    // this.ViewBag.Picture = originalPicture;

                    this.ViewBag.Profile = profile;
                }
                catch (LinkedInApiException ex)
                {
                    this.ViewBag.ProfileError = ex.ToString();
                }
                catch (Exception ex)
                {
                    this.ViewBag.ProfileError = ex.ToString();
                }

                watch.Stop();
                this.ViewBag.ProfileDuration = watch.Elapsed;
            }

            return(this.View());
        }