SNS Count Cache がGoogle+のデータを読まなくなった

2017/07/20WordPress

私が運用しているwordpressサイトにて、SNS Count Cache プラグインからGoogle+のデータを読めなくなりました。この現象は複数のブログで発生しており、私のところでは7月18日夜から発生したブログと7月19日昼からのブログ、そしてまだエラーが発生していないブログに別れています。

以下、現象と原因についてのメモ。

(Google+のデータが取得できません)

エラーメッセージ

wp-cron.phpからsns-count-cacheを実行した時にエラーになります。今まで正常に動作していたコードですし、エラーが発生していないブログと突き合わせても特に問題はなさそうです。

PHP Fatal error:  Uncaught Error: Call to undefined function get_cache_key() in XXX/wp-content/plugins/sns-count-cache/includes/class-scc-share-second-cache-engine.php:326
Stack trace:
#0 XXX/wp-content/plugins/sns-count-cache/sns-count-cache.php(1908): SCC_Share_Second_Cache_Engine->get_cache(Array)
#1 XXX/wp-content/plugins/sns-count-cache/includes/class-scc-cache-engine.php(108): SNS_Count_Cache->order(Object(SCC_Share_Base_Cache_Engine), 'get_second_cach...', Array)
#2 XXX/wp-content/plugins/sns-count-cache/includes/class-scc-share-base-cache-engine.php(416): SCC_Cache_Engine->delegate_order('get_second_cach...', Array)
#3 XXX/wp-content/plugins/sns-count-cache/includes/class-scc-share-cache-engine.php(204): SCC_Share_Base_Cache_Engine->get_cache(Array)
#4 XXX/wp-content/plugins/sns-count-cache/includes/class-scc-share-base-cache-engine.php(202): SCC_Share_C in XXX/plugins/sns-count-cache/includes/class-scc-share-second-cache-engine.php on line 326

Google+からのデータ取得方法

Google Plusボタンを表示するコードを取得して、帰ってきたHTMLの中からシェア数を拾い出しているようです。力技です。

Load the following URL: https://plusone.google.com/_/+1/fastbutton?url=URLENCODED_URI (UPDATED URL, see note below *)

URLENCODED_URI is the site you wish to know the number of +1’s for, e.g. http://www.google.com (http%3A%2F%2Fwww.google.com)

For example, fetch the URI https://plusone.google.com/_/+1/fastbutton?url=http://www.google.com/ (UPDATED URI) and locate the first occurance of window.__SSR = {'c’: 32414.0 ,’si’. Preferably use regexp for this, but I’ll leave the implementation to you and your chosen programming language (server side or client side).

The float number following 'c’ is the number of +1’s the site have. For google.com this is 32,414. Don’t worry about the float, you can safely convert it to an integer.

javascript – How do I get the counter of a google plus +1 button? – Stack Overflow

SNS Count Cache では“https://apis.google.com/_/+1/fastbutton”が使われていますが、原理は一緒です。

なぜ読めなくなったか

読み込み高速化のために、Google Plusボタンの仕様が変更されたようです。下記メッセージ(6/16)に“Beginning in a few weeks”とありますので、そろそろ影響が出てきたということでしょうか。

Beginning in a few weeks, clicking the +1 button will open a streamlined new Google+ sharing dialog, and the G+1 button will no longer display a +1 count. If you’re a publisher, you can rest assured that these +1s do not affect search ranking and the size and layout of the button will remain the same.

Making the G+1 button load more quickly The G+1 button is shown billions of …

実際に “https://apis.google.com/_/+1/fastbutton” を叩いてみても、シェア数は返ってきません。

対処

とりあえず、うちのブログは Google+ からのデータ取得を停止しました。エラーがでてキャッシュが正常に行われないよりはマシですので。
取得できるAPIが見つかるまでは我慢かな……

WordPress

Posted by ず@沖縄