I am using a wp_remote_get via Wordpress to retrieve information about a vimeo video. 80% of the time is works great, but there is this 20% factor, where the name, thumbnail_url and title are blank. The response from the wp_remote_retrieve_body is functioning, just the data is not there.
Here is my code:
function mmd_get_vimeo_info( $video_id )
{
$VimeoCommunicationLink = sanitize_text_field(stripslashes(mmd_vimeoteaser_ReadSetting("`VIMEO_JSON_LINK")));
$VimeoConnectLink = $VimeoCommunicationLink . $video_id;
$request = wp_remote_get( esc_url_raw($VimeoConnectLink) );
if ('error' == $request || is_wp_error($request))
return "";
$response = wp_remote_retrieve_body( $request );
if ('error' == $response || is_wp_error($response))
return "";
$video_array = json_decode( $response, true );
// Looking for [title], [thumbnail_url] [duration]
return $video_array;
}
typically, this returns the following:
$VimeoVideoData = mmd_get_vimeo_info( $VideoId );
$VideoThumbNail = $VimeoVideoData['thumbnail_url'];
$VideoTitle = $VimeoVideoData['title']; // Title of video
$Length = $VimeoVideoData['duration'];
It appeared that this had something to do with domain privacy and that was confirmed when I got a 403 within domain_status_code. Here is the dump, when using print_r($response, true);
(
[type] => video
[version] => 1.0
[provider_name] => Vimeo
[provider_url] => https://vimeo.com/
[html] => <iframe src="https://player.vimeo.com/video/304219740?h=914796992d&app_id=122963" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe>
[width] => 640
[height] => 360
[domain_status_code] => 403
[video_id] => 304219740
[uri] => /videos/304219740
)
The mystery is, the video plays on the same site, it just does not always return "[title], [thumbnail_url] or [duration]. I found this page: https://developer.vimeo.com/api/oembed/videos Ït says: To get the complete response, including the private metadata, send the Referer header with the request, and set its value to the video's whitelisted domain.
But I have no idea how to do this with :
wp_remote_get and wp_remote_retrieve_body. wp_remote_retrieve_header($request, $header);
Any ideas? `Could use some help. The successful playing of the video, is the mystery. I just need to consistently get the thumbnail, duration and title.