I was receiving this error when enabling the seo feature to print the comments in the page:

Notice: Undefined property: stdClass::$data in _fb_social_comments_seo() (line 288 of sites/all/modules/fb_social/plugins/fb_plugin/comments.inc).

Warning: Invalid argument supplied for foreach() in _fb_social_comments_seo_view() (line 301 of sites/all/modules/fb_social/plugins/fb_plugin/comments.inc).

This was only happening on pages without comments. The functions were not checking for null values. The fix I implemented is below. All I did was check if the variables existed via isset. I am not familiar with generating patches, if someone more experienced could take care of that it would be great.

Line 288

if(isset($result->$url->data)) {
      	$comments = _fb_social_comments_seo_view($result->$url->data);
} else {
	$comments = "";
}

Line 301:

if(isset($comments)) {
		foreach ($comments as $comment) {
			$result .= '<li>' . fb_social_comments_seo_comment_view($comment);
			if (isset($comment -> comments)){
				$result .= '<ul>';
				foreach ($comment -> comments -> data as $subcomment) {
					$result .= '<li>' . fb_social_comments_seo_comment_view($subcomment) . '</li>';
				}
				$result .= '</ul>';
			}
			$result .= '</li>';
		}
	}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

johnzzon’s picture

Actually the problem seems to be that Facebook changed the structure of the returned JSON.
One simple line fixed this for me:

Line 288 - Original

$comments = _fb_social_comments_seo_view($result->$url->data);

Line 288 - Fix:

$comments = _fb_social_comments_seo_view($result->$url->comments->data);
johnzzon’s picture

FileSize
716 bytes

Right, gave this patch thingy a try, please correct me if I did it wrong.

TechNikh’s picture

Status: Active » Reviewed & tested by the community

I had the same issue. The above patch fixed it.

klausi’s picture

Version: 7.x-2.0-beta4 » 7.x-2.x-dev
Status: Reviewed & tested by the community » Needs work

patch does not apply.

klausi’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
604 bytes

Rerolled.

pianomansam’s picture

Confirmed that this is taken care of in 7.x-2.x-dev. Can we get this pushed to a non-dev version?

SocialNicheGuru’s picture

I was running the fb_social dev version and the patch still applied

cblanglois’s picture

This worked perfect for me, thanks!

cblanglois’s picture

Issue summary: View changes

After nullify $comments if $result->$url->data is not set, otherwise return $comments gives error.

SocialNicheGuru’s picture

Issue summary: View changes

There might be times when $comments is not defined.

add the following to top of function:

// initialize
  $comments = array();
ferdi’s picture

Committed , thanks !

  • Commit caf13e0 on 7.x-2.x by ferdi:
    Issue #1485838 by klausi, johnzzon | michaelfillier: Comments SEO does...

  • Commit 3315ebf on 6.x-2.x by ferdi:
    Issue #1485838 by klausi, johnzzon | michaelfillier: Comments SEO does...
ferdi’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

trong.nguyen.tcec’s picture

Error in log:
PHP Fatal error: Function name must be a string in DOCUMENT_ROOT\modules\field_ui\field_ui.admin.inc on line 154

Try to use this code.

/**
 * Get comments from facebook using graph api
 */
function _fb_social_comments_seo($url, $nr_comments, $cache_length) {
    $cache_key = md5('fb_social_comments_seo' . $url);

    $comments = "";
    if ($cache = cache_get($cache_key)) {
        $comments = $cache->data;
    } else {
        $req_url = "https://graph.facebook.com/comments/?ids=" . $url;
        if ($nr_comments) {
            $req_url .= "&limit=$nr_comments";
        }
        $request = drupal_http_request($req_url);

        if ($request->code == 200) {
            $result = json_decode($request->data);
            if (isset($result->{$url}) && isset($result->{$url}->comments)) {
                $comments = _fb_social_comments_seo_view($result->{$url}->comments->data);
            }
        }
        cache_set($cache_key, $comments, 'cache', REQUEST_TIME + (60 * $cache_length));
    }

    return $comments;
}