Facebook Sharer.php "The message could not be posted to this Wall." Error

UPDATE: As of 2014-01-16 10:17 (GMT+8), this issue has been fixed. View the bug report.



Facebook Sharer Error.

Got this error message after updating Wordpress plugin for one of the site that I help maintain.




Debugging



When inspecting the network tab for the ajax request, I saw this error description in the response.
for (;;);{"__ar":1,"error":1367001,"errorSummary":"Could not post to Wall","errorDescription":"The message could not be posted to this Wall.","payload":null,"bootloadable":{},"ixData":[]}
After searching in Google, most people suggest that error 1367001 is due to incomplete URL format. But for my case, the URL is in complete form.

So I did a comparison with the sharer on Techcrunch page.


I noticed the difference is mainly on the attachment section.
attachment[params][images][0]


Conclusion


Its Facebook sharer permission issue. Seems like Facebook sharer will include og:image tags images as attachment when you have multiple og:image meta tags, and there seems to be permission issue with posting the attachment to user's wall.

This only happen recently. So until Facebook fixes this... nothing much we can do other than limit to only 1 og:image tag on our sites.





Solution


Limit to just 1 of og:image.  Simple solution that works.



You can try with these sample:

1 image:
https://www.facebook.com/sharer/sharer.php?u=http://vulcanpost.com/statics/html/2014/facebook-sharer-with-1-image.html

3 image:
https://www.facebook.com/sharer/sharer.php?u=http://vulcanpost.com/statics/html/2014/facebook-sharer-with-3-images.html



Solution (For Facebook Wordpress Plugins)



  1. Open /wp-content/plugins/facebook/open-graph-protocol.php,
  2. Find "get_og_images" function and add in the following code

if (count( $og_images ) === 1) {
return $og_images; // Force only 1 image.
}

Your function should be like this:
/**
* Identify image attachments related to the post.
*
* Request the full size of the attachment, not necessarily the same as the size used in the post.
*
* @since 1.5
*
* @param stdClass|WP_Post $post WordPress post of interest
* @return array {
* Open Graph protocol image structured data
*
* @type string URL of the image
* @type array associative array of image data
* }
*/
public static function get_og_images( $post ) {
$og_images = array();
if ( ! $post || ! isset( $post->ID ) )
return $og_images;
// does current post type and the current theme support post thumbnails?
if ( post_type_supports( get_post_type( $post ), 'thumbnail' ) && function_exists( 'has_post_thumbnail' ) && has_post_thumbnail() ) {
list( $post_thumbnail_url, $post_thumbnail_width, $post_thumbnail_height ) = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
$image = self::attachment_to_og_image( get_post_thumbnail_id( $post->ID ) );
if ( isset( $image['url'] ) && ! isset( $og_images[ $image['url'] ] ) )
$og_images[ $image['url'] ] = $image;
unset( $image );
}
// get image attachments
if ( function_exists( 'get_attached_media' ) ) {
$images = get_attached_media( 'image', $post->ID );
if ( ! empty( $images ) ) {
if (count( $og_images ) === 1) {
return $og_images; // Force only 1 image.
}
foreach( $images as $i ) {
if ( ! isset( $i->ID ) )
continue;
$image = self::attachment_to_og_image( $i->ID );
if ( ! isset( $image['url'] ) || isset( $og_images[ $image['url'] ] ) )
continue;
$og_images[ $image['url'] ] = $image;
if ( count( $og_images ) === self::MAX_IMAGE_COUNT )
return $og_images;
}
}
unset( $images );
}
// test for WP_Embed handled images
if ( ! empty( $post->post_content ) ) {
// Instagram
preg_match_all( '#\s*http://instagr(\.am|am\.com)/p/(.*)/\s*#i', $post->post_content, $matches );
if ( isset( $matches[2] ) ) {
foreach( $matches[2] as $instagram_id ) {
$instagram_url = esc_url_raw( 'http://instagram.com/p/' . $instagram_id . '/media/?size=l', array( 'http' ) );
if ( ! $instagram_url || isset( $og_images[$instagram_url] ) )
continue;
$og_images[$instagram_url] = array( 'url' => $instagram_url );
unset( $instagram_url );
}
}
unset( $matches );
}
// add gallery content
if ( function_exists( 'get_post_galleries' ) ) {
// use get_post_galleries function from WP 3.6+
$galleries = get_post_galleries( $post, false );
foreach( $galleries as $gallery ) {
// use ids to request full-size image URI
if ( ! ( isset( $gallery['ids'] ) && $gallery['ids'] ) )
continue;
$gallery['ids'] = explode( ',', $gallery['ids'] );
foreach( $gallery['ids'] as $attachment_id ) {
$image = self::attachment_to_og_image( $attachment_id );
if ( ! isset( $image['url'] ) || isset( $og_images[ $image['url'] ] ) )
continue;
$og_images[ $image['url'] ] = $image;
if ( count( $og_images ) === self::MAX_IMAGE_COUNT )
return $og_images;
unset( $image );
}
}
unset( $galleries );
} else {
// extract full-size images from gallery shortcode
$og_images = self::gallery_images( $post, $og_images );
}
return $og_images;
}







References:
http://stackoverflow.com/questions/3944268/facebook-sharer-php-how-to-have-multiple-ogimage-tags

Comments

  1. Thank you for sharing the video of liquid cooling for computers. Keep sharing.

    ReplyDelete
  2. Skype Tapatalk users can´t see the videos. How can I
    do to solve it? I saw this thread, but I am ...

    Skype
    Technical Help

    ReplyDelete

Post a Comment

Popular posts from this blog

[Magento] Create Contact Form with Dynamic Recipient

[Azure Websites PHP] Cross Domain request results in blank response page after Preflight HTTP OPTIONS