Thursday, 14 January 2016

Drupal 7 - Open Graph Selected images are not sharing into Facebook when both Image field and Description box contains images.

Basic Configuration to test and solve this problem:
Create a content type with One Image Field and Body Field (Those are needed to replicate it)

Successful Scenarios:
Scenario 1:
1. Add new content for the above content type with images upload by Image Tool only (Image Field)
3. Select image from those uploaded images using Open Graph Configuration and saved the node.
4. If we are sharing that article, whatever the image that we have shared, that will get shared in Facebook

Scenario 2:
1. Add new content for the above content type with images upload by body field only (Through Text Editor Media / IMCE)
3. Select image from those uploaded images using Open Graph Configuration and saved the node.
4. If we are sharing that article, whatever the image that we have shared, that will get shared in Facebook

Unsuccessful Scenario:
1. Add new content for the above content type with images upload by both image tool and body field (Editor).
2. Select an image from those uploaded images using Open Graph Configuration and saved the node.
3. If we are sharing that article, whatever the image that we are trying to share, will not get shared into Facebook.

The original problem behind this is opengraph_meta module will generate images array with URL, alt and title sort of text using a function called "harvest_images_from_node". this function definition is available in opengraph_meta.common.inc file. after forming the array of images, if we remove duplicate images and order them as needed by system, this image sharing issue will get resolved. To do that follow below steps.

Solution:
1. Open file opengraph_meta.common.inc
2. Search for function "harvest_images_from_node".
3. there replace return of result stagement with below code.
    Existing Line: return $ret;
    Update TO:
        $ret = array_map("unserialize", array_unique(array_map("serialize", $ret))); // Remove Duplicates
        $result = array_values($ret); // Reorder them
        return $result; // Return Result images.
       
Now check Unsuccessful Scenario. It will work fine. if it is not working, please clear Facebook cache for existing web pages.

No comments:

Post a Comment

Thank you so much for providing your valuable feedback. I will will look into them and update my skills & technologies accordingly.