dilame / instagram-private-api

NodeJS Instagram private API SDK. Written in TypeScript.
MIT License
5.83k stars 1.13k forks source link

JSON question... #1494

Open DevStreamLine opened 2 years ago

DevStreamLine commented 2 years ago

Hello,

I am a somewhat newbie with node.js but I have a beginner problem.

I am doing this:

const resStory = await ig.publish.story({file: response.buffer});
await clearStateAndLogout(ig);
return `${JSON.stringify(resStory)}`;

but the result comes back as shown below and is not JSON, it looks like it may be because it has \" delimeters but I am not sure.

So, how do I get JSON to return back from my function?

{
  "result": "{\"media\":{\"taken_at\":1628463655,\"pk\":\"2636066664144626986\",\"id\":\"2636066664144626986_48361711762\",\"device_timestamp\":1628463655131,\"media_type\":1,\"code\":\"CSVMKogluUq\",\"client_cache_key\":\"MjYzNjA2NjY2NDE0NDYyNjk4Ng==.2\",\"filter_type\":0,\"is_unified_video\":false,\"user\":{\"pk\":48361711762,\"is_private\":false,\"profile_pic_url\":\"https://instagram.fsig1-1.fna.fbcdn.net/v/t51.2885-19/44884218_345707102882519_2446069589734326272_n.jpg?_nc_ht=instagram.fsig1-1.fna.fbcdn.net&_nc_ohc=DTLSrWbkEzYAX-U9E3v&edm=AL4D0a4BAAAA&ccb=7-4&oh=5c13f4cfd3b5f5e8a477482e978cdd62&oe=6117CFCF&_nc_sid=712cc3&ig_cache_key=YW5vbnltb3VzX3Byb2ZpbGVfcGlj.2-ccb7-4\",\"is_verified\":false,\"follow_friction_type\":0,\"has_anonymous_profile_picture\":true,\"can_boost_post\":false,\"can_see_organic_insights\":false,\"show_insights_terms\":false,\"reel_auto_archive\":\"on\",\"is_unpublished\":false,\"allowed_commenter_type\":\"any\",\"account_badges\":[],\"fbid_v2\":\"17841448472875213\"},\"caption_is_edited\":false,\"like_and_view_counts_disabled\":false,\"is_commercial\":true,\"commerciality_status\":\"commercial\",\"is_paid_partnership\":false,\"playlist_eligibility\":false,\"comment_likes_enabled\":false,\"comment_threading_enabled\":false,\"has_more_comments\":false,\"max_num_visible_preview_comments\":2,\"preview_comments\":[],\"can_view_more_preview_comments\":false,\"comment_count\":0,\"hide_view_all_comment_entrypoint\":false,\"image_versions2\":{\"candidates\":[{\"width\":954,\"height\":1696,\"url\":\"https://scontent-iad3-2.cdninstagram.com/v/t51.2885-15/e35/233941014_114679730905477_4003046939045054935_n.jpg?se=8&_nc_ht=scontent-iad3-2.cdninstagram.com&_nc_cat=101&_nc_ohc=E-ydlLkwGEEAX-wgwwJ&edm=AO5kzY0BAAAA&ccb=7-4&oh=f25aa7cb54cc09e39fb7585bd890c6fb&oe=6112C9DD&_nc_sid=560b88&ig_cache_key=MjYzNjA2NjY2NDE0NDYyNjk4Ng%3D%3D.2-ccb7-4\",\"scans_profile\":\"e35\",\"estimated_scans_sizes\":[16193,32387,48581,64775,80969,97730,118310,131758,145745]},{\"width\":360,\"height\":640,\"url\":\"https://scontent-iad3-2.cdninstagram.com/v/t51.2885-15/e35/p360x360/233941014_114679730905477_4003046939045054935_n.jpg?_nc_ht=scontent-iad3-2.cdninstagram.com&_nc_cat=101&_nc_ohc=E-ydlLkwGEEAX-wgwwJ&edm=AO5kzY0BAAAA&ccb=7-4&oh=66031d8e54a0a210a7abb9f404c908a5&oe=6112AD5F&_nc_sid=560b88&ig_cache_key=MjYzNjA2NjY2NDE0NDYyNjk4Ng%3D%3D.2-ccb7-4\",\"scans_profile\":\"e35\",\"estimated_scans_sizes\":[4844,9688,14532,19376,24220,30234,390482,43596,43596]}]},\"original_width\":954,\"original_height\":1696,\"caption_position\":0,\"is_reel_media\":true,\"timezone_offset\":0,\"like_count\":0,\"has_liked\":false,\"likers\":[],\"photo_of_you\":false,\"can_see_insights_as_brand\":false,\"caption\":null,\"can_viewer_save\":false,\"organic_tracking_token\":\"eyJ2ZXJzaW9uIjo1LCJwYXlsb2FkIjp7ImlzX2FuYWx5dGljc190cmFja2VkIjpmYWxzZSwidXVpZCI6IjUxZWZhY2JjZWU2NTQ4OWViY2ZiYWQyMWZhZDUxMzgyMjYzNjA2NjY2NDE0NDYyNjk4NiIsInNlcnZlcl90b2tlbiI6IjE2Mjg0NjM2NTgwOTZ8MjYzNjA2NjY2NDE0NDYyNjk4Nnw0ODM2MTcxMTc2MnxlYmJjNTgzMjNkM2M2MTRlMzkzMjI1MDc3MjBlYTVkMWJlOGFmYzYwYmM5YTk4MGVkNzc2MjI0MDQwY2M5ZDYxIn0sInNpZ25hdHVyZSI6IiJ9\",\"expiring_at\":1628550055,\"sharing_friction_info\":{\"should_have_sharing_friction\":false,\"bloks_app_url\":null},\"product_type\":\"story\",\"is_in_profile_grid\":false,\"profile_grid_control_enabled\":false,\"deleted_reason\":0,\"integrity_review_decision\":\"pending\",\"can_reshare\":true,\"can_reply\":false,\"story_is_saved_to_archive\":true,\"story_static_models\":[],\"viewers\":[],\"viewer_count\":0,\"fb_viewer_count\":null,\"viewer_cursor\":null,\"total_viewer_count\":0,\"multi_author_reel_names\":[],\"supports_reel_reactions\":true,\"can_send_custom_emojis\":true,\"show_one_tap_fb_share_tooltip\":true,\"has_shared_to_fb\":0,\"has_shared_to_fb_dating\":0,\"source_type\":3},\"upload_id\":\"1628463655131\",\"status\":\"ok\"}"
}
Nerixyz commented 2 years ago
  1. What do you want this function to return and why/what do you want to do with the return-value?
  2. You don't have to use the template string.
  3. You're returning a string (with JSON in it).
  4. In the sample you linked there's incomplete JSON. You probably just forgot the starting { (I edited your issue). The structure of your data in typescript syntax would be { result: string }. But your string contains a JSON payload. I'd guess this is sone kind of web framework. Your framework is calling JSON.stringify at a later stage again. You probably just want to return the object.