osompress / genesis-simple-share

Plugin: Genesis Simple Share
36 stars 16 forks source link

LinkedIn count no longer working #72

Closed nickcernis closed 7 years ago

nickcernis commented 8 years ago

We have seen several reports of broken LinkedIn share buttons in Rainmaker support today. The LinkedIn button is not loading or displaying the count. Demo URLs:

The console shows a 400 (Bad Request) error against the LinkedIn count API URL:

https://www.linkedin.com/countserv/count/share?format=jsonp&url=http%3A%2F%2Fwww.copyblogger.com%2Femail-marketing-defined%2F&callback=jQuery111302880242855132005_1463058833340&_=1463058833341

Visiting that link shows an “invalid callback parameter” message.

Findings so far

NicktheGeek commented 8 years ago

ok, pushed a fix for this to master, develop, rainmaker-master, and rainmaker-develop. Pick your poison to test it.

Test Scenario:

Note It seems LinkedIn is blocking requests via the JS so we may need additional workaround to get the counts back.

Test Verification:

Other Features/Areas Affected: N/A

NicktheGeek commented 8 years ago

ok, found a solution that works for LinkedIn to get the counts despite the API changes

nickcernis commented 8 years ago

Thanks, Nick! Looks good in WordPress [http://debug.wpdemo.me/test-word-wrapping/ ]:

test_word_wrapping_-_my_blog

Have not tested Rainmaker yet.

In case the PHP count fallback causes problems for any users, an alternative fix may be to specify the JS callback function name manually to exclude punctuation and numbers. i.e. Use $.ajaxSetup({ jsonpCallback: "simpleShare" }); before using $.getJSON() in jquery.sharrre.js around line 490. (We have seen support issues with the PHP count method used for Google+ due to server security rules, but not very often – happy to monitor this.)

NicktheGeek commented 8 years ago

We have seen support issues with the PHP count method used for Google+ due to server security rules, but not very often – happy to monitor this

The issue is more than just the callback. When I removed that and tested I got a different fail error based on the domain not being allowed. It seems LinkedIn changed their security and are now blocking the JS request methods like this. Which is why I had to rewrite to use the .php file, not dealing with the callback itself.

nickcernis commented 8 years ago

When I removed that and tested I got a different fail error based on the domain not being allowed.

Removing the callback=? param altogether turns the JSONP request into a regular JSON one, I believe:

If the URL includes the string "callback=?" (or similar, as defined by the server-side API), the request is treated as JSONP instead. See the discussion of the jsonp data type in $.ajax() for more details. – http://api.jquery.com/jQuery.getJSON/#jsonp

A JSON request will trigger the cross-domain error you saw because JSON requests are subject to the same-origin policy, unlike JSONP. I get the same error when pasting jQuery.getJSON('https://www.linkedin.com/countserv/count/share?format=jsonp&url=http%3A%2F%2Fexample.com%2F', function (json) { console.log(json); }); into the console on http://www.copyblogger.com/email-marketing-defined/, for example (missing callback param drops the request to JSON).

Seems crazy that LinkedIn would start validating the callback parameter name all of a sudden. Your PHP idea is really smart and looks good – thank you for jumping on this so fast.

Just waiting on RM sites to update to test it there. (I am still currently seeing LinkedIn errors on http://nick-cernis.pro01.rmkr.net/admin/admin.php?page=universal-settings&tab=traffic still.)

NicktheGeek commented 8 years ago

The RM sites should have updated by now. Likely you have cached JS.

nickcernis commented 8 years ago

Hmm. I used Empty Cache and Hard Reload and tried two other browsers but don't see the latest JS. Guessing http://nick-cernis.pro01.rmkr.net/ may not be updating hourly.

@katyfb13 Please could I have your help testing this fix for Rainmaker at some point?

Test verification:
eugenoprea commented 8 years ago

I can verify that the LinkedIn button shows on the cbmdev02 site, on the "develop" branch.

screen shot 2016-05-13 at 17 22 06
NicktheGeek commented 8 years ago

Update Genesis Simple Share to address LinkedIn API change

NicktheGeek commented 8 years ago

This is deployed for WP.org as version 1.0.7

NicktheGeek commented 7 years ago

closing as this should be in production