I'm looking to retrieve Instagram user account information such as followers, following, and account name.
The endpoint I have been using is:
https://www.instagram.com/{username}/?__a=1
By including the specific username
in the endpoint URL, I am able to access a JSON page containing various data points like follower count, following count, and the account name.
In my WordPress website, I have implemented the following code snippet in the functions.php
file and created a shortcode for easy display on a page:
function insta_shortcode_func() {
$request = wp_remote_get('https://www.instagram.com/barkobco/?__a=1');
if (is_wp_error($request)) {
return false; // Exit early
}
$body = wp_remote_retrieve_body($request);
$data = json_decode($body);
return $data -> { 'count'};
}
add_shortcode('count_of_followers', 'insta_shortcode_func');
Despite implementing this code, the desired data is not being displayed. I am specifically aiming to show the follower count, following count, and the account name.