ramtinak / InstagramApiSharp

A complete Private Instagram API for .NET (C#, VB.NET).
MIT License
781 stars 239 forks source link

Live IGTV share api has been changed! #409

Closed mohsen-rasouli closed 4 months ago

mohsen-rasouli commented 3 years ago

Hello. I'm using "instagram-private-api" to develop my personal project for live classes. but recently I can't share my IG Live directly after I finish my live. All of Lives Archive into the "Live Archive" and I should Share it manually.

I used this API: /api/v1/live/add_post_live_to_igtv/

but recently, the callback of that api is empty. what should I do? Thank You /.

ramtinak commented 3 years ago

Hi, This API is deprecated by Instagram. Add/remove post live is deprecated by Instagram. https://github.com/ramtinak/InstagramApiSharp/issues/244#issuecomment-757090070

Regards.

mohsen-rasouli commented 3 years ago

Is there any api or way to share archives live to post? Because it it is possible to do this on official app. So I think there is a way to do that!

Aydin47 commented 3 years ago

Hi @mohsen-rasouli, Idk if this helps your problem for posting a live video after finishing : 1: LiveProcessor.EndAsync(broadcastID) 2: via (/igtv/igtv_creation_tools/) get the resposne. 3: Get the Thumbnails with /live/{0}/get_post_live_thumbnails/ (0 is BroadcastID) which gives you the list of thumbnail urls 4: Download the Thumbnail and make a class InstaImageUpload with : Height = 1920, Width = 1080, File.ReadAllBytes(@"thumbnail path in your pc") 5:This part was tricky for me... First you send the resuest with this parameters var photoUploadParamsObj = new JObject { {"upload_id", uploadId}, {"media_type", "1"}, {"broadcast_id", BroadCastID}, {"retry_context", GetRetryContext()}, {"is_post_live_igtv", "1"}, {"image_compression", "{\"lib_name\":\"moz\",\"lib_version\":\"3.1.m\",\"quality\":\"95\"}"}, // quality 0 ? {"xsharing_user_ids", "[]"} }; var photoUploadParams = JsonConvert.SerializeObject(photoUploadParamsObj); request = _httpHelper.GetDefaultRequest(HttpMethod.Get, photoUri, _deviceInfo); this will give you a status 200, then you send another request with: var imageContent = new ByteArrayContent(imageBytes); imageContent.Headers.Add("Content-Type", "application/octet-stream"); request.Content = imageContent; request.Headers.Add("X-Entity-Type", "image/jpeg"); request.Headers.Add("Offset", "0"); request.Headers.Add("X-Instagram-Rupload-Params", photoUploadParams); request.Headers.Add("X-Entity-Name", photoEntityName); request.Headers.Add("X-Entity-Length", imageBytes.Length.ToString()); request.Headers.Add("X_FB_PHOTO_WATERFALL_ID", waterfallId);
request.Headers.Add("X-FB-Client-IP", "True");
request.Headers.Add("Connection", "close");
If this result is succesfull its time to cinfigure it to IGTV: 6: Using /media/configure_to_igtv/ : var data = new JObject { { "_csrftoken", _user.CsrfToken}, // ok {"_uid", _user.LoggedInUser.Pk.ToString()}, // ok {"_uuid", _deviceInfo.DeviceGuid.ToString()}, // ok {"timezone_offset", InstaApiConstants.TIMEZONE_OFFSET.ToString() }, // ok {"igtv_ads_toggled_on", false}, // ok {"title", title}, // ok {"caption", caption}, // ok {"igtv_share_preview_to_feed", true }, // ok {"upload_id", uploadId }, // ok {"device_id", _deviceInfo.DeviceId }, // ok {"source_type", "4" }, // ok {"keep_shoppable_products", false }, // ok {"igtv_composer_session_id", Guid.NewGuid().ToString() }, // ok { "device", new JObject{ {"manufacturer", _deviceInfo.HardwareManufacturer}, {"model", _deviceInfo.DeviceModelIdentifier}, {"android_version", int.Parse(_deviceInfo.AndroidVer.APILevel)}, {"android_release", _deviceInfo.AndroidVer.VersionNumber} } }, { "extra", new JObject { {"source_width", "576" /videoUploadOption.SourceWidth/}, {"source_height", "944" /videoUploadOption.SourceHeight/} } } }; var request = _httpHelper.GetSignedRequest(HttpMethod.Post, instaUri, _deviceInfo, data); then: request.Headers.Add("retry_context", retryContext); request.Headers.Add("is_igtv_video", "true");

            request.Headers.Add("IG-U-IG-DIRECT-REGION-HINT", "FRC");
            request.Headers.Add("IG-U-DS-USER-ID", _user.LoggedInUser.Pk.ToString());
            request.Headers.Add("IG-U-RUR", "RVA");

            request.Headers.Add("DEBUG-IG-USER-ID", _user.LoggedInUser.Pk.ToString());
            request.Headers.Add("Priority", "u=3");
            request.Headers.Add("X-Bloks-Is-Panorama-Enabled", "true");

send the request and your done. request.Headers.Add("X-FB-Client-IP", "true"); request.Headers.ConnectionClose = true; var response = await _httpRequestProcessor.SendAsync(request);

Aydin47 commented 3 years ago

https://github.com/Aydin47/InstagramApiSharp/blob/master/samples/Examples/Samples/GoLiveAndPostLiveAfter.cs

mohsen-rasouli commented 3 years ago

https://github.com/Aydin47/InstagramApiSharp/blob/master/samples/Examples/Samples/GoLiveAndPostLiveAfter.cs

Can I Speak Persian/Farsi? I have some question that I cant tell it in EN.

Aydin47 commented 3 years ago

https://github.com/Aydin47/InstagramApiSharp/blob/master/samples/Examples/Samples/GoLiveAndPostLiveAfter.cs

Can I Speak Persian/Farsi? I have some question that I cant tell it in EN.

bale hatman

mohsen-rasouli commented 3 years ago

salam va ehteram. aval mamnun babate pasokhgooee. dovom sepase bikaran baaabate in ketabkhoone berooz. tooye api haye instagram tanha ketabkhooneii hast ke berooz hast.

man be nowee daram rooye php kar mikonam. hamoontor ke tooye avavlin comment goftam requset /api/v1/live/add_post_live_to_igtv/ ba parametr haye zir ersal mikardam:

   $ig->request('live/add_post_live_to_igtv/')
         ->addPost('_csrftoken', $ig->client->getToken())
         ->addPost('_uuid', $ig->uuid)
         ->addPost('broadcast_id', '{$bId}')
         ->addPost('cover_upload_id', "{$upload_id}")
         ->addPost('description', "{$bDescription}")
         ->addPost('title', "{$bTitle}")
         ->addPost('internal_only', false)
         ->addPost('igtv_share_preview_to_feed', true)
         ->getDecodedResponse();

ke bad az medati az kar oftad va null ya empty barmigardoond. man baraye upload cover moskeli nadaram va moskelesh ro hal kardam.

beresim be methodi ke shoma moaredi kardin: man bad az live ye request be /igtv/igtv_creation_tools/ ferestadam ke status=>ok bargardoond. bad az upload cover va deyafre upload_id mikhatam az requset /media/configure_to_igtv estefade konam amma nafahmidam che datahaii samte server ersal kardin. barche asas broadcast_id ro mifahme ke live ro IGTV kone mishe behem towzih bedin? toye request shoma broadcast id nist!

age baratoon maghdoore be telegramam payam bedin: @mr_mohsen_rasouli

mamnun

Aydin47 commented 3 years ago

@mohsen-rasouli

POST /rupload_igphoto/"UploadID"0"Photohash" in request e upload e Thumbnail hastesh. In request ro besazid

`

                var photoUploadParamsObj = new JObject
                {
                {"upload_id", uploadId},
                {"media_type", "1"},
                {"broadcast_id", BID},
                {"retry_context", retryContext},
                {"is_post_live_igtv", "1"},
                {"image_compression", "{\"lib_name\":\"moz\",\"lib_version\":\"3.1.m\",\"quality\":\"95\"}"}, // quality 0 ?
                {"xsharing_user_ids", "[]"} // check also withouth []
                }

            retryContext = 
            new JObject
            {
                {"num_step_auto_retry", 0},
                {"num_reupload", 0},
                {"num_step_manual_retry", 0}
            }.ToString(Formatting.None)

`

ino Serialize konid, Hamintori ke mibinin instagram BroadcastID ro too upload e thumbnail (cover) mifreste... kamelesh:

'

           var photoUploadParams = JsonConvert.SerializeObject(photoUploadParamsObj);
            var imageBytes = image.ImageBytes ?? File.ReadAllBytes(image.Uri);
            var imageContent = new ByteArrayContent(imageBytes);
            imageContent.Headers.Add("Content-Type", "application/octet-stream");
            request = _httpHelper.GetDefaultRequest(HttpMethod.Post, photoUri, _deviceInfo);
            request.Content = imageContent;
            request.Headers.Add("X-Entity-Type", "image/jpeg");
            request.Headers.Add("Offset", "0");
            request.Headers.Add("X-Instagram-Rupload-Params", photoUploadParams);
            request.Headers.Add("X-Entity-Name", photoEntityName);
            request.Headers.Add("X-Entity-Length", imageBytes.Length.ToString());
            request.Headers.Add("X_FB_PHOTO_WATERFALL_ID", waterfallId);                                                                                 
            request.Headers.Add("X-FB-Client-IP", "True");                               
            request.Headers.Add("Connection", "close");                                    
            response = await _httpRequestProcessor.SendAsync(request);

' var photoEntityName = $"{uploadId}0{photoHashCode}"; var waterfallId = Guid.NewGuid().ToString();

baghiash mesle bala ghesmate 6 e, dige inja broadcastID ferestade nemishe... age codetoon ro bebinam mitoonam bishtar komak konam (ketabkhoonei ke man bash kar mikonam male man nist man khodam chand rooz pish fork kardam az inja :D)

mohsen-rasouli commented 3 years ago

@mohsen-rasouli

POST /rupload_igphoto/"UploadID"0"Photohash" in request e upload e Thumbnail hastesh. In request ro besazid

`

                var photoUploadParamsObj = new JObject
                {
                {"upload_id", uploadId},
                {"media_type", "1"},
                {"broadcast_id", BID},
                {"retry_context", retryContext},
                {"is_post_live_igtv", "1"},
                {"image_compression", "{\"lib_name\":\"moz\",\"lib_version\":\"3.1.m\",\"quality\":\"95\"}"}, // quality 0 ?
                {"xsharing_user_ids", "[]"} // check also withouth []
                }

            retryContext = 
            new JObject
            {
                {"num_step_auto_retry", 0},
                {"num_reupload", 0},
                {"num_step_manual_retry", 0}
            }.ToString(Formatting.None)

`

ino Serialize konid, Hamintori ke mibinin instagram BroadcastID ro too upload e thumbnail (cover) mifreste... kamelesh:

'

           var photoUploadParams = JsonConvert.SerializeObject(photoUploadParamsObj);
            var imageBytes = image.ImageBytes ?? File.ReadAllBytes(image.Uri);
            var imageContent = new ByteArrayContent(imageBytes);
            imageContent.Headers.Add("Content-Type", "application/octet-stream");
            request = _httpHelper.GetDefaultRequest(HttpMethod.Post, photoUri, _deviceInfo);
            request.Content = imageContent;
            request.Headers.Add("X-Entity-Type", "image/jpeg");
            request.Headers.Add("Offset", "0");
            request.Headers.Add("X-Instagram-Rupload-Params", photoUploadParams);
            request.Headers.Add("X-Entity-Name", photoEntityName);
            request.Headers.Add("X-Entity-Length", imageBytes.Length.ToString());
            request.Headers.Add("X_FB_PHOTO_WATERFALL_ID", waterfallId);                                                                                 
            request.Headers.Add("X-FB-Client-IP", "True");                               
            request.Headers.Add("Connection", "close");                                    
            response = await _httpRequestProcessor.SendAsync(request);

' var photoEntityName = $"{uploadId}0{photoHashCode}"; var waterfallId = Guid.NewGuid().ToString();

baghiash mesle bala ghesmate 6 e, dige inja broadcastID ferestade nemishe... age codetoon ro bebinam mitoonam bishtar komak konam (ketabkhoonei ke man bash kar mikonam male man nist man khodam chand rooz pish fork kardam az inja :D)

mailton bedin ta baratoon ersal konam ketabkhoone i ke daram roosh kar mikonam. be telegram @mr_mohsen_rasouli ya mr.mohsen.rasouli@gmail.com

mohsen-rasouli commented 3 years ago

man aks ke samte server mifrestam ye chizi shabihe in behem bar migardoone... photohash nadare:

Array
(
    [media] => Array
        (
            [taken_at] => 1615498484
            [pk] => 2527306924136118596
            [id] => 2527306924136118596_8445534497
            [device_timestamp] => 336882168665313
            [media_type] => 1
            [code] => CMSzEHbhLlE
            [client_cache_key] => MjUyNzMwNjkyNDEzNjExODU5Ng==.2
            [filter_type] => 0
            [user] => Array
                (
                    [pk] => 8888888
                    [username] => user
                    [full_name] =>  شیدا
                    [is_private] => 
                    [profile_pic_url] => https://instagram.fgyd4-2.fna.fbcdn.net/v/t51.2885-19/s150x150/39777003_2013569795361373_1257355730353127424_n.jpg?tp=1&_nc_ht=instagram.fgyd4-2.fna.fbcdn.net&_nc_ohc=y7v4IuOouj8AX8SBs9L&oh=58a1c3422c236e9652f6b3a223e8d1fd&oe=6075A563
                    [profile_pic_id] => 1858667650626132889_8445534497
                    [has_anonymous_profile_picture] => 
                    [can_boost_post] => 1
                    [can_see_organic_insights] => 1
                    [show_insights_terms] => 
                    [reel_auto_archive] => on
                    [is_unpublished] => 
                    [allowed_commenter_type] => any
                    [account_badges] => Array
                        (
                        )

                    [fbid_v2] => 17841408594915691
                )

            [can_viewer_reshare] => 1
            [caption_is_edited] => 
            [like_and_view_counts_disabled] => 
            [is_paid_partnership] => 
            [comment_likes_enabled] => 
            [comment_threading_enabled] => 
            [has_more_comments] => 
            [max_num_visible_preview_comments] => 2
            [preview_comments] => Array
                (
                )

            [can_view_more_preview_comments] => 
            [comment_count] => 0
            [hide_view_all_comment_entrypoint] => 
            [image_versions2] => Array
                (
                    [candidates] => Array
                        (
                            [0] => Array
                                (
                                    [width] => 751
                                    [height] => 751
                                    [url] => https://instagram.fgyd4-1.fna.fbcdn.net/v/t51.2885-15/e35/158372465_185872119708490_6990741471327040963_n.jpg?tp=1&_nc_ht=instagram.fgyd4-1.fna.fbcdn.net&_nc_cat=110&_nc_ohc=JXeVGoNh1G8AX_BUk2Z&oh=bc3aa73a46f3c411a91b606306fedc7e&oe=607527E4&ig_cache_key=MjUyNzMwNjkyNDEzNjExODU5Ng%3D%3D.2
                                    [scans_profile] => e35
                                    [estimated_scans_sizes] => Array
                                        (
                                            [0] => 4813
                                            [1] => 9627
                                            [2] => 14440
                                            [3] => 19254
                                            [4] => 24067
                                            [5] => 29050
                                            [6] => 35167
                                            [7] => 39164
                                            [8] => 43322
                                        )

                                )

                            [1] => Array
                                (
                                    [width] => 360
                                    [height] => 360
                                    [url] => https://instagram.fgyd4-1.fna.fbcdn.net/v/t51.2885-15/e35/s360x360/158372465_185872119708490_6990741471327040963_n.jpg?tp=1&_nc_ht=instagram.fgyd4-1.fna.fbcdn.net&_nc_cat=110&_nc_ohc=JXeVGoNh1G8AX_BUk2Z&oh=9b162baa93164ee758250b559c146467&oe=6073BD72&ig_cache_key=MjUyNzMwNjkyNDEzNjExODU5Ng%3D%3D.2
                                    [scans_profile] => e35
                                    [estimated_scans_sizes] => Array
                                        (
                                            [0] => 2134
                                            [1] => 4269
                                            [2] => 6404
                                            [3] => 8538
                                            [4] => 10673
                                            [5] => 13323
                                            [6] => 172077
                                            [7] => 19212
                                            [8] => 19212
                                        )

                                )

                        )

                )

            [original_width] => 751
            [original_height] => 751
            [boosted_status] => not_boosted
            [photo_of_you] => 
            [can_see_insights_as_brand] => 
            [caption] => Array
                (
                    [pk] => 17889245683964060
                    [user_id] => 8888888
                    [text] => this is for test2
                    [type] => 1
                    [created_at] => 1615498485
                    [created_at_utc] => 1615498485
                    [content_type] => comment
                    [status] => Active
                    [bit_flags] => 0
                    [did_report_as_spam] => 
                    [share_enabled] => 
                    [user] => Array
                        (
                            [pk] => 888888
                            [username] => user
                            [full_name] =>  شیدا
                            [is_private] => 
                            [profile_pic_url] => https://instagram.fgyd4-2.fna.fbcdn.net/v/t51.2885-19/s150x150/39777003_2013569795361373_1257355730353127424_n.jpg?tp=1&_nc_ht=instagram.fgyd4-2.fna.fbcdn.net&_nc_ohc=y7v4IuOouj8AX8SBs9L&oh=58a1c3422c236e9652f6b3a223e8d1fd&oe=6075A563
                            [profile_pic_id] => 1858667650626132889_8445534497
                            [has_anonymous_profile_picture] => 
                            [can_boost_post] => 1
                            [can_see_organic_insights] => 1
                            [show_insights_terms] => 
                            [reel_auto_archive] => on
                            [is_unpublished] => 
                            [allowed_commenter_type] => any
                            [account_badges] => Array
                                (
                                )

                            [fbid_v2] => 17841408594915691
                        )

                    [is_covered] => 
                    [media_id] => 2527306924136118596
                    [private_reply_status] => 0
                )

            [fb_user_tags] => Array
                (
                    [in] => Array
                        (
                        )

                )

            [can_viewer_save] => 1
            [organic_tracking_token] => eyJ2ZXJzaW9uIjo1LCJwYXlsb2FkIjp7ImlzX2FuYWx5dGljc190cmFja2VkIjp0cnVlLCJ1dWlkIjoiZmZjZWJhNTc3N2EwNDdiYjg0OTI5NGRhNGUxNGYxZGYyNTI3MzA2OTI0MTM2MTE4NTk2Iiwic2VydmVyX3Rva2VuIjoiMTYxNTQ5ODQ4ODM5NnwyNTI3MzA2OTI0MTM2MTE4NTk2fDg0NDU1MzQ0OTd8NjcwZmM3NmVmMDgwOTE3YzU4ZmZkMjg5MzY1ZmZkYTRiYzM4ZmE1MzcwZWUyNGYwYTZkZDZkNDc0NGZjMzBiNiJ9LCJzaWduYXR1cmUiOiIifQ==
            [sharing_friction_info] => Array
                (
                    [should_have_sharing_friction] => 
                    [bloks_app_url] => 
                )

            [is_in_profile_grid] => 
            [profile_grid_control_enabled] => 
            [deleted_reason] => 0
            [integrity_review_decision] => pending
        )

    [upload_id] => 336882168665313
    [status] => ok
)