Home › Forums › Basel support forum › Instagram not pulling images
Instagram not pulling images
- This topic has 9 replies, 3 voices, and was last updated 6 years, 5 months ago by
Elise Noromit.
-
AuthorPosts
-
September 10, 2018 at 6:35 pm #76476
PedramParticipantHello,
I’ve been having issues with instagram widget. I have searched and found a ticket that was submitted to you earlier and you had suggested to add the following code to functions.php:
unction basel_scrape_instagram( $username, $slice = 9 ) {
$username = strtolower( $username );
$by_hashtag = ( substr( $username, 0, 1 ) == ‘#’ );
$transient_name = ‘instagram-media-new1-‘ . sanitize_title_with_dashes( $username );
$instagram = get_transient( $transient_name );if ( false === $instagram ) {
$request_param = ( $by_hashtag ) ? ‘explore/tags/’ . substr( $username, 1) : trim( $username );
$remote = wp_remote_get( ‘https://instagram.com/’. $request_param );if ( is_wp_error( $remote ) ) {
return new WP_Error( ‘site_down’, esc_html__( ‘Unable to communicate with Instagram.’, ‘basel’ ) );
}if ( 200 != wp_remote_retrieve_response_code( $remote ) ) {
return new WP_Error( ‘invalid_response’, esc_html__( ‘Instagram did not return a 200.’, ‘basel’ ) );
}$shards = explode( ‘window._sharedData = ‘, $remote[‘body’] );
$insta_json = explode( ‘;</script>’, $shards[1] );
$insta_array = json_decode( $insta_json[0], TRUE );if ( ! $insta_array ){
return new WP_Error( ‘bad_json’, esc_html__( ‘Instagram has returned invalid data.’, ‘basel’ ) );
}if ( isset( $insta_array[‘entry_data’][‘ProfilePage’][0][‘graphql’][‘user’][‘edge_owner_to_timeline_media’][‘edges’] ) ) {
$images = $insta_array[‘entry_data’][‘ProfilePage’][0][‘graphql’][‘user’][‘edge_owner_to_timeline_media’][‘edges’];
} elseif( $by_hashtag && isset( $insta_array[‘entry_data’][‘TagPage’][0][‘graphql’][‘hashtag’][‘edge_hashtag_to_media’][‘edges’] ) ) {
$images = $insta_array[‘entry_data’][‘TagPage’][0][‘graphql’][‘hashtag’][‘edge_hashtag_to_media’][‘edges’];
} else {
return new WP_Error( ‘bad_json_2’, esc_html__( ‘Instagram has returned invalid data.’, ‘basel’ ) );
}if ( ! is_array( $images ) ) {
return new WP_Error( ‘bad_array’, esc_html__( ‘Instagram has returned invalid data.’, ‘basel’ ) );
}$instagram = array();
foreach ( $images as $image ) {
$image = $image[‘node’];
$caption = esc_html__( ‘Instagram Image’, ‘basel’ );
if ( ! empty( $image[‘edge_media_to_caption’][‘edges’][0][‘node’][‘text’] ) ) $caption = $image[‘edge_media_to_caption’][‘edges’][0][‘node’][‘text’];$image[‘thumbnail_src’] = preg_replace( “/^https:/i”, “”, $image[‘thumbnail_src’] );
$image[‘thumbnail’] = preg_replace( “/^https:/i”, “”, $image[‘thumbnail_resources’][0][‘src’] );
$image[‘medium’] = preg_replace( “/^https:/i”, “”, $image[‘thumbnail_resources’][2][‘src’] );
$image[‘large’] = $image[‘thumbnail_src’];$type = ( $image[‘is_video’] ) ? ‘video’ : ‘image’;
$instagram[] = array(
‘description’ => $caption,
‘link’ => ‘//instagram.com/p/’ . $image[‘shortcode’],
‘comments’ => $image[‘edge_media_to_comment’][‘count’],
‘likes’ => $image[‘edge_liked_by’][‘count’],
‘thumbnail’ => $image[‘thumbnail’],
‘medium’ => $image[‘medium’],
‘large’ => $image[‘large’],
‘type’ => $type
);
}// do not set an empty transient – should help catch private or empty accounts
if ( ! empty( $instagram ) ) {
$instagram = base64_encode( maybe_serialize( $instagram ) );
set_transient( $transient_name, $instagram, apply_filters( ‘null_instagram_cache_time’, HOUR_IN_SECONDS * 2 ) );
}
}
if ( ! empty( $instagram ) ) {
$instagram = maybe_unserialize( base64_decode( $instagram ) );
return array_slice( $instagram, 0, $slice );
} else {
return new WP_Error( ‘no_images’, esc_html__( ‘Instagram did not return any images.’, ‘basel’ ) );
}
}But it’s not working for me. When I add it my website goes blank and i don’t see any errors.
Can you please advise?
Thank you!
September 10, 2018 at 7:00 pm #76482
Elise NoromitMemberHello,
This code is not valid anymore. Please describe your problem in details and provide admin access to your site.
Best Regards
September 10, 2018 at 11:09 pm #76509
PedramParticipantHi,
Instagram is not showing images and instead shows an error ‘Instagram did not return a 200.’ >> this is the error.Can you please let me know how I can get it working?
Thanks!
September 11, 2018 at 6:40 am #76547
Artem TemosKeymasterPlease, provide us your admin access so we can login and check this on your side.
Thank you in advance.
September 11, 2018 at 10:51 pm #76735
PedramParticipantPlease see the private content I shared below.
September 12, 2018 at 5:22 am #76745
Elise NoromitMemberHello,
Please provide your logoin URL
Best Regards
September 12, 2018 at 5:50 pm #76846
PedramParticipantSee below! thanks
September 12, 2018 at 8:25 pm #76858
Elise NoromitMemberHello,
The issue has been fixed. I have deleted
@
and now it works: http://prntscr.com/ktpdprBest Regards
September 13, 2018 at 9:20 pm #77035
PedramParticipantThank you!
September 14, 2018 at 6:04 am #77046
Elise NoromitMemberYou are welcome! If you have any questions please feel free to contact us.
Best Regards
-
AuthorPosts
The topic ‘Instagram not pulling images’ is closed to new replies.
- You must be logged in to create new topics. Login / Register