jtsternberg / DsgnWrks-Instagram-Importer

Backup your instagram photos & display your instagram archive. Supports importing to custom post-types & adding custom taxonomies.
http://wordpress.org/extend/plugins/dsgnwrks-instagram-importer/
33 stars 17 forks source link

Carousel posts download the wrong image #52

Open c99koder opened 5 years ago

c99koder commented 5 years ago

The hack you're using in download_media_url() will always use the URL of the first image in the carousel instead of using the correct item from the graphql array in the json response, so it just downloads the thumbnail / cover image multiple times instead of each image in the carousel

c99koder commented 5 years ago

I've fixed it locally by passing the $index from the carousel image loop through to download_media_url and added the following to get the correct URL from the edge_sidecar_to_children array node:

if ( !empty( $result->graphql->shortcode_media->edge_sidecar_to_children)) {
    $tmp = download_url( $result->graphql->shortcode_media->edge_sidecar_to_children->edges[$index]->node->display_url );
} else if (
    ! empty( $result->graphql->shortcode_media->display_url )
…

There's probably a better way to fix it, just a quick hack I added to get it working for now

ni-ka commented 5 years ago

I confirm - trying your fix @c99koder but no success. Does it still work on your end? I've added the $index param as an optional param with default value 0

c99koder commented 5 years ago

@ni-ka it's still working for me, I've uploaded my changes to a branch you can try here: https://github.com/c99koder/DsgnWrks-Instagram-Importer/commit/d2524396c378e0104cd35bf5898d15a9ff791226

ni-ka commented 5 years ago

Thanks @c99koder - works nicely! I had omitted an optional parameter before the index.

ni-ka commented 5 years ago

@jtsternberg would you be interested in a pull request with the changes @c99koder which fix carousel posts?

jtsternberg commented 5 years ago

Yes, sounds good.

c99koder commented 5 years ago

I've submitted a pull request