Home › Forums › WoodMart support forum › Problem refresh instagram
Problem refresh instagram
- This topic has 4 replies, 2 voices, and was last updated 6 years, 9 months ago by
Elise Noromit.
-
AuthorPosts
-
May 22, 2018 at 2:10 pm #58828
cri.galiaParticipantHello!
I have a problem with refresh instagram in the site: http://www.progettiverdi.com/I set also the function woodmart_scrape_instagram but when I put an image in instagram the site don’t refresh.
Can you help me please?Thanks
Cristinafunction woodmart_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.’, ‘woodmart’ ) );
}if ( 200 != wp_remote_retrieve_response_code( $remote ) ) {
return new WP_Error( ‘invalid_response’, esc_html__( ‘Instagram did not return a 200.’, ‘woodmart’ ) );
}$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.’, ‘woodmart’ ) );
}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.’, ‘woodmart’ ) );
}if ( ! is_array( $images ) ) {
return new WP_Error( ‘bad_array’, esc_html__( ‘Instagram has returned invalid data.’, ‘woodmart’ ) );
}$instagram = array();
foreach ( $images as $image ) {
$image = $image[‘node’];
$caption = esc_html__( ‘Instagram Image’, ‘woodmart’ );
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 = woodmart_compress( maybe_serialize( $instagram ) );
set_transient( $transient_name, $instagram, apply_filters( ‘null_instagram_cache_time’, HOUR_IN_SECONDS * 2 ) );
}
}
if ( ! empty( $instagram ) ) {
$instagram = maybe_unserialize( woodmart_decompress( $instagram ) );
return array_slice( $instagram, 0, $slice );
} else {
return new WP_Error( ‘no_images’, esc_html__( ‘Instagram did not return any images.’, ‘woodmart’ ) );
}
}May 22, 2018 at 2:52 pm #58838
Elise NoromitMemberHello,
Please install and activate free Transients Manager. Then, navigate to Tools > Transients > Insert “Instagram” in search and delete them all.
Check the issue again.
Best Regards
May 22, 2018 at 8:27 pm #58882
cri.galiaParticipantHello, I have followed your instructions but when I insert a new image in instagram not working.
Instagram page is:
https://www.instagram.com/progettiverdi/But in the site the image not the last http://www.progettiverdi.com/
Why?
Thanks
CristinaMay 23, 2018 at 4:55 am #58891
cri.galiaParticipantToday there is a new image. But to refresh you must wait some hours?
May 23, 2018 at 7:12 am #58901
Elise NoromitMemberHello,
Yes, it is in cash for a few hours. Please wait.
Best Regards
-
AuthorPosts
The topic ‘Problem refresh instagram’ is closed to new replies.
- You must be logged in to create new topics. Login / Register