The addition of Facebook Open Graph Code does not work for the attachment pages of the media library

I have in my code header a code that correctly creates Open Graph tags for pages, publications, and so on. However, when I try to share a publication as an attachment from the Media Object Debugger complains

        "Error while parsing the input URL, no data was cached or no data was retrieved."

I have reviewed the header of the generated pages and they look identical to other pages, publications and other types of custom publishing. We were using Yoast and I thought that was the problem, but I turned it off and I still do not work.

For example. the WordPress URL is

                    http://example.com/part-150-study/

Which redirects correctly (301) to

                    http://example.com/wp-content/uploads/part-150-study.pdf

When I use the OG Object Debugger from Facebook, it displays a 206 response code.

The following will be treated as a redirection by the robot:

HTTP redirection
A  label
A  label

The final URL, from which we have tried to extract the metadata, is highlighted in bold.

It also shows that the last page (PDF) is a 301 redirect.

Here is the code I put in my header. Which (again) works well for all types of publication. But not attachments.

function insert_fb_in_head () {

$ og_title = get_post_meta (get_the_ID (), _yoast_wpseo_title, true);
if (! $ og_title)
$ og_title = get_the_title ();

echo (& # 39;& # 39 ;. PHP_EOL);
echo (& # 39;& # 39 ;. PHP_EOL);
echo (& # 39;& # 39 ;. PHP_EOL);
echo (& # 39;& # 39 ;. PHP_EOL);
echo (& # 39;& # 39 ;. PHP_EOL);

if (has_post_thumbnail ($ post-> ID)) {// the message has a selected image, use a default image
$ thumbnail_src = wp_get_attachment_image_src (get_post_thumbnail_id ($ post-> ID), & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp; & nbsp;)
echo (& # 39;& # 39 ;. PHP_EOL);
echo (& # 39;& # 39 ;. PHP_EOL);
echo (& # 39;& # 39 ;. PHP_EOL);
}

$ default_image = "http://example.com/wp-content/uploads/airplane-250.png";
echo (& # 39;& # 39 ;. PHP_EOL);
echo (& # 39;& # 39 ;. PHP_EOL);
echo (& # 39;& # 39 ;. PHP_EOL);
}
add_action (& # 39; wp_head & # 39 ;, & # 39; insert_fb_in_head & # 39 ;, 5);

Here is the section of an example HTML rendered source code:

  
  
  
  
  
  
  
  

YET, I've asked this question in another thread and it has been suggested to try using Yoast and change the setting in the "Redirect Attachment URLs to Part" section. attached? " But that made no difference and, in fact, deactivating Yoast made no difference.

Ideas?