'',
'user_id' => 'self',
),
$atts
);
// Attributes
$atts = shortcode_atts(
array(
'auth_token' => '',
'user_id' => 'self',
),
$atts
);
/**
* instagram_api_curl_connect()
* Gets the Instagram API.
* Returns json decoded response.
*
* @param string $api_url
* @return string
*/
function instagram_api_curl_connect( $api_url ) {
$connection_c = curl_init(); // initializing
curl_setopt( $connection_c, CURLOPT_URL, $api_url ); // API URL to connect
curl_setopt( $connection_c, CURLOPT_RETURNTRANSFER, 1 ); // return the result, do not print
curl_setopt( $connection_c, CURLOPT_TIMEOUT, 20 );
$json_return = curl_exec( $connection_c ); // connect and get json data
curl_close( $connection_c ); // close connection
return json_decode( $json_return ); // decode and return
}
$your_token = $atts[ 'auth_token' ];
$ig_user_id = $atts[ 'user_id' ];
$img_count = 1;
if ( $ig_user_id != 'self' ) {
$user_search = instagram_api_curl_connect( "https://api.instagram.com/v1/users/search?q=" . $ig_user_id . "&access_token=" . $your_token );
$ig_user_id = $user_search->data[0]->id;
}
$instagram_url = "https://api.instagram.com/v1/users/" . $ig_user_id . "/media/recent/?access_token=" . $your_token;
$remote_wp = wp_remote_get( $instagram_url );
$instagram_response = json_decode( $remote_wp[ 'body' ] );
if ( $remote_wp[ 'response' ][ 'code' ] == 200 ) {
foreach ( $instagram_response->data as $m ) {
$link = $m->link;
$path = parse_url( $link, PHP_URL_PATH );
$params = explode( '/', $path );
$embededUrl = "https://instagram.com/p/" . $params[2] . "/media/?size=l";
echo '';
// more parameters here https://www.instagram.com/developer/endpoints/users/#get_users_media_recent
if ( $img_count == 1 ) break;
}
} elseif ( $remote_wp[ 'response' ][ 'code' ] == 400 ) {
echo '' . $remote_wp[ 'response' ][ 'message' ] . ': ' . $instagram_response->meta->error_message;
}
return $remote_wp;
}
add_shortcode( 'instagram_latest', 'latest_instagram' );