goinsta
goinsta copied to clipboard
Unable to marshal struct Item
I've successfully written a tiny wrapper around your project to use it via gomobile. So far, I've been able to login, search for users, etc.
The gomobile bindings only allow functions to return basic datatypes: int
, char
, string
, []byte
, etc. As a consequence, I need to marshal some results into strings before returning.
One issue I've run into which I don't quite know how to solve is that the Item
struct fails to be marshalled. It ends up in an infinite loop somehow and eventually fails with a stack overflow error:
ig, err := login()
user, _ := ig.Profiles.ByName("instagram")
feed := user.Feed()
feed.Next()
items := feed.Items
item := items[0]
b, _ := json.Marshal(item)
fmt.Println(string(b))
}
runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow
runtime stack:
runtime.throw(0x738da0, 0xe)
/usr/local/go/src/runtime/panic.go:608 +0x72
runtime.newstack()
/usr/local/go/src/runtime/stack.go:1008 +0x729
runtime.morestack()
/usr/local/go/src/runtime/asm_amd64.s:429 +0x8f
goroutine 19 [running]:
bytes.(*Buffer).WriteByte(0xc0000bc2c0, 0x7b, 0x0, 0x0)
/usr/local/go/src/bytes/buffer.go:265 +0xb1 fp=0xc020bee318 sp=0xc020bee310 pc=0x4c9781
encoding/json.(*structEncoder).encode(0xc000431110, 0xc0000bc2c0, 0x71fa20, 0xc00046a120, 0x199, 0x520100)
/usr/local/go/src/encoding/json/encode.go:632 +0x4a fp=0xc020bee478 sp=0xc020bee318 pc=0x52563a
encoding/json.(*structEncoder).encode-fm(0xc0000bc2c0, 0x71fa20, 0xc00046a120, 0x199, 0xc000460100)
/usr/local/go/src/encoding/json/encode.go:661 +0x64 fp=0xc020bee4b8 sp=0xc020bee478 pc=0x52e904
encoding/json.(*ptrEncoder).encode(0xc0000a6508, 0xc0000bc2c0, 0x708ce0, 0xc00046a120, 0x16, 0x700100)
/usr/local/go/src/encoding/json/encode.go:788 +0xb3 fp=0xc020bee500 sp=0xc020bee4b8 pc=0x526e83
encoding/json.(*ptrEncoder).encode-fm(0xc0000bc2c0, 0x708ce0, 0xc00046a120, 0x16, 0xc000460100)
/usr/local/go/src/encoding/json/encode.go:793 +0x64 fp=0xc020bee540 sp=0xc020bee500 pc=0x52eb04
encoding/json.(*encodeState).reflectValue(0xc0000bc2c0, 0x708ce0, 0xc00046a120, 0x16, 0xc000460100)
/usr/local/go/src/encoding/json/encode.go:333 +0x82 fp=0xc020bee578 sp=0xc020bee540 pc=0x5231a2
encoding/json.interfaceEncoder(0xc0000bc2c0, 0x6ec440, 0xc0001fc000, 0x194, 0x100)
/usr/local/go/src/encoding/json/encode.go:619 +0xab fp=0xc020bee5c0 sp=0xc020bee578 pc=0x5253fb
encoding/json.(*structEncoder).encode(0xc000430d50, 0xc0000bc2c0, 0x734be0, 0xc0001fc000, 0x199, 0x100)
/usr/local/go/src/encoding/json/encode.go:647 +0x280 fp=0xc020bee720 sp=0xc020bee5c0 pc=0x525870
encoding/json.(*structEncoder).encode-fm(0xc0000bc2c0, 0x734be0, 0xc0001fc000, 0x199, 0x730100)
...
If you have any insight into why this might be happening, I can try and come up with a PR to solve this.
Seems a problem of json package.
I ran your script here and got no problems. This was the output:
{
"taken_at": 1544296347,
"pk": 1930020110127549904,
"id": "1930020110127549904_25025320",
"comments_disabled": false,
"device_timestamp": 154429593946257,
"media_type": 1,
"code": "BrIzxCBg03Q",
"client_cache_key": "MTkzMDAyMDExMDEyNzU0OTkwNA==.2",
"filter_type": 0,
"carousel_parent_id": "",
"user": {
"pk": 25025320,
"username": "instagram",
"full_name": "Instagram",
"biography": "",
"profile_pic_url": "https://instagram.fcpq2-1.fna.fbcdn.net/vp/b842b706ed884b2e6d9d1ad8d2940967/5C8BB15B/t51.2885-19/s150x150/14719833_310540259320655_1605122788543168512_a.jpg",
"email": "",
"phone_number": "",
"is_business": false,
"gender": 0,
"profile_pic_id": "1360316971354486387_25025320",
"has_anonymous_profile_picture": false,
"is_private": false,
"is_unpublished": false,
"allowed_commenter_type": "",
"is_verified": true,
"media_count": 0,
"follower_count": 0,
"following_count": 0,
"following_tag_count": 0,
"profile_context_mutual_follow_ids": null,
"profile_context": "",
"geo_media_count": 0,
"external_url": "",
"has_biography_translation": false,
"external_lynx_url": "",
"biography_with_entities": {
"raw_text": "",
"entities": null
},
"usertags_count": 0,
"has_chaining": false,
"is_favorite": false,
"is_favorite_for_stories": false,
"is_favorite_for_highlights": false,
"can_be_reported_as_fraud": false,
"show_shoppable_feed": false,
"shoppable_posts_count": 0,
"reel_auto_archive": "on",
"has_highlight_reels": false,
"public_email": "",
"public_phone_number": "",
"public_phone_country_code": "",
"contact_phone_number": "",
"city_id": 0,
"city_name": "",
"address_street": "",
"direct_messaging": "",
"latitude": 0,
"longitude": 0,
"category": "",
"business_contact_method": "",
"include_direct_blacklist_status": false,
"hd_profile_pic_url_info": {
"height": 0,
"url": "",
"width": 0
},
"hd_profile_pic_versions": null,
"school": {},
"byline": "",
"mutual_followers_count": 0,
"is_call_to_action_enabled": false,
"fb_page_call_to_action_id": "",
"zip": "",
"friendship_status": {
"incoming_request": false,
"followed_by": false,
"outgoing_request": false,
"following": false,
"blocking": false,
"is_private": false,
"muting": false,
"is_muting_reel": false
}
},
"can_viewer_reshare": true,
"caption": {
"pk": 17992369978118358,
"user_id": 25025320,
"text": "Photo by @smallstepsaregiantleaps \nGreetings earthlings. This is 7-year-old kid astronaut and first-grader Harrison Sheldon. 🚀He’s the star of @smallstepsaregiantleaps, a photo project that his dad, editorial photographer and nonprofit media consultant Aaron Sheldon, started when Harrison was 4 years old. \nInstagram: Aaron, is there a game attached to the project?\nAaron: When we decide to visit a place for the project, we talk about what we might see there. During our visit, I have Harry compare what we thought we might see with the actual experience. My favorite part of each shoot is hearing his thoughts about the places and what he liked about each place as we look at the pictures together over a post-mission doughnut, cookie or ice-cream cone. \nIG: Astronaut Harrison, what’s the best part of being an astronaut?\nHarrison: Exploring places, meeting astronauts, bouncing on hotel beds, having cool exploring gear and snacks. \nIG: Astronaut Harrison, what do you want to be when you grow up?\nHarrison: Superhero.\nAaron: What if your plan to create your own superpowers doesn’t work out? What would you be if you can’t be a superhero?\nHarrison: Police officer and construction worker in space. \nCheck out today’s story to explore along with Harrison and Aaron on some of their adventures.",
"type": 1,
"created_at": 1544296348,
"created_at_utc": 1544296348,
"content_type": "comment",
"status": "Active",
"bit_flags": 0,
"user": {
"pk": 25025320,
"username": "instagram",
"full_name": "Instagram",
"biography": "",
"profile_pic_url": "https://instagram.fcpq2-1.fna.fbcdn.net/vp/b842b706ed884b2e6d9d1ad8d2940967/5C8BB15B/t51.2885-19/s150x150/14719833_310540259320655_1605122788543168512_a.jpg",
"email": "",
"phone_number": "",
"is_business": false,
"gender": 0,
"profile_pic_id": "1360316971354486387_25025320",
"has_anonymous_profile_picture": false,
"is_private": false,
"is_unpublished": false,
"allowed_commenter_type": "",
"is_verified": true,
"media_count": 0,
"follower_count": 0,
"following_count": 0,
"following_tag_count": 0,
"profile_context_mutual_follow_ids": null,
"profile_context": "",
"geo_media_count": 0,
"external_url": "",
"has_biography_translation": false,
"external_lynx_url": "",
"biography_with_entities": {
"raw_text": "",
"entities": null
},
"usertags_count": 0,
"has_chaining": false,
"is_favorite": false,
"is_favorite_for_stories": false,
"is_favorite_for_highlights": false,
"can_be_reported_as_fraud": false,
"show_shoppable_feed": false,
"shoppable_posts_count": 0,
"reel_auto_archive": "on",
"has_highlight_reels": false,
"public_email": "",
"public_phone_number": "",
"public_phone_country_code": "",
"contact_phone_number": "",
"city_id": 0,
"city_name": "",
"address_street": "",
"direct_messaging": "",
"latitude": 0,
"longitude": 0,
"category": "",
"business_contact_method": "",
"include_direct_blacklist_status": false,
"hd_profile_pic_url_info": {
"height": 0,
"url": "",
"width": 0
},
"hd_profile_pic_versions": null,
"school": {},
"byline": "",
"mutual_followers_count": 0,
"is_call_to_action_enabled": false,
"fb_page_call_to_action_id": "",
"zip": "",
"friendship_status": {
"incoming_request": false,
"followed_by": false,
"outgoing_request": false,
"following": false,
"blocking": false,
"is_private": false,
"muting": false,
"is_muting_reel": false
}
},
"did_report_as_spam": false,
"media_id": 1930020110127549904,
"has_translation": false
},
"caption_is_edited": false,
"like_count": 882985,
"has_liked": false,
"top_likers": [
"enkisoma",
"mello_gabriel04",
"rafah_andreolii"
],
"likers": null,
"comment_likes_enabled": true,
"comment_threading_enabled": true,
"has_more_comments": true,
"max_num_visible_preview_comments": 2,
"preview_comments": [],
"comment_count": 10874,
"photo_of_you": false,
"usertags": {
"in": null
},
"fb_user_tags": {
"in": null
},
"can_viewer_save": true,
"organic_tracking_token": "eyJ2ZXJzaW9uIjo1LCJwYXlsb2FkIjp7ImlzX2FuYWx5dGljc190cmFja2VkIjp0cnVlLCJ1dWlkIjoiZDhiNjE5ZmIxN2MxNDZhNjg5YmJhYmE0ZjkxMjIxZTQxOTMwMDIwMTEwMTI3NTQ5OTA0Iiwic2VydmVyX3Rva2VuIjoiMTU0NDQ1Mjc2MTM3MXwxOTMwMDIwMTEwMTI3NTQ5OTA0fDk0MTg3NDg0MzN8ZGMyMjc4MjA1YTUxNjdmNWRiOWZlYjkzODRhZGRhYzZmZDQ4MjEzNzkxZjU0OGQ5NzE1NzFiNjYzOGExNzlmMSJ9LCJzaWduYXR1cmUiOiIifQ==",
"image_versions2": {
"candidates": [
{
"width": 1080,
"height": 1080,
"url": "https://instagram.fcpq2-1.fna.fbcdn.net/vp/fdc3ccf36a269295a955165d1390761e/5CA4ADCA/t51.2885-15/e35/45404528_196007357911855_2495553744348210134_n.jpg?_nc_ht=instagram.fcpq2-1.fna.fbcdn.net&se=8&ig_cache_key=MTkzMDAyMDExMDEyNzU0OTkwNA%3D%3D.2"
},
{
"width": 240,
"height": 240,
"url": "https://instagram.fcpq2-1.fna.fbcdn.net/vp/1c8c67bc5376ca6307fbca97bf64483d/5C9E84C2/t51.2885-15/e35/s240x240/45404528_196007357911855_2495553744348210134_n.jpg?_nc_ht=instagram.fcpq2-1.fna.fbcdn.net&ig_cache_key=MTkzMDAyMDExMDEyNzU0OTkwNA%3D%3D.2"
}
]
},
"original_width": 1080,
"original_height": 1080,
"location": {
"pk": 212928653,
"name": "Miami Beach, Florida",
"address": "",
"city": "",
"short_name": "Miami Beach",
"lng": -80.1341,
"lat": 25.813,
"external_source": "facebook_places",
"facebook_places_id": 108260802527498
},
"lat": 25.813,
"lng": -80.1341,
"story_events": null,
"story_hashtags": null,
"story_polls": null,
"story_feed_media": null,
"story_sound_on": null,
"creative_config": null,
"story_locations": null,
"story_sliders": null,
"story_questions": null,
"story_product_items": null,
"supports_reel_reactions": false,
"show_one_tap_fb_share_tooltip": false,
"has_shared_to_fb": 0,
"Mentions": null
}
Is this exactly the code that you are running this problem?
Try serializing one item at a time.
That's weird. I just tried it and I still hit the same exception.
This is the entirety of my code:
func TestItemMarshal(t *testing.T) {
require := require.New(t)
ig, err := login()
require.Nil(err, fmt.Sprintf("Failed to login: %v", err))
require.NotNil(ig)
user, _ := ig.Profiles.ByName("instagram")
feed := user.Feed()
feed.Next()
items := feed.Items
item := items[0]
b, _ := json.Marshal(item)
fmt.Println(string(b))
}
And yes, I'm still hitting the same exception.
My go version is:
go version go1.11.2 linux/amd64