Simple Machines Community Forum

SMF Support => SMF 2.0.x Support => Topic started by: spiros on December 24, 2016, 08:02:19 AM

Title: Lost FB likes after moving to SSL
Post by: spiros on December 24, 2016, 08:02:19 AM
I have changed to SSL and I lost all FB likes. I found these intructions (http://stackoverflow.com/questions/29532848/lost-all-likes-while-moving-to-https):

And it looks like this bit:

<meta property="og:url"               content="' . $context['canonical_url'] . '" />
http://www.simplemachines.org/community/index.php?topic=546773.0

Should be modified so that og:url points to the http version of the page. How can this be done?

Title: Re: Lost FB likes after moving to SSL
Post by: spiros on December 24, 2016, 09:53:50 AM
OK, I got it:

<meta property="og:url" content="http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], '" />

But adding it did not seem to restore the Likes. Hmm, perhaps because it does not give a canonical URL.

So how to get canonical URL with http and not https?
Title: Re: Lost FB likes after moving to SSL
Post by: aegersz on December 24, 2016, 04:23:41 PM
I dropped the fb likes and karma in favor of the Advanced Reputation System mod ... you may want to check it out.
Title: Re: Lost FB likes after moving to SSL
Post by: spiros on December 24, 2016, 06:50:04 PM
Not an option due to the high number of likes etc in some pages which are quite valuable.
Title: Re: Lost FB likes after moving to SSL
Post by: aegersz on December 24, 2016, 07:09:49 PM
Understood -- but ARS can co-exist with your fb likes, i guess.

I obviously really like the ARS and my members actually told me to ditch the fb likes mod.
Title: Re: Lost FB likes after moving to SSL
Post by: Arantor on December 25, 2016, 03:55:57 AM
<meta property="og:url"               content="' . str_replace('https://', 'http://', $context['canonical_url'], 1) . '" />
Title: Re: Lost FB likes after moving to SSL
Post by: CMOBOSS on December 25, 2016, 04:58:41 AM
ARS appears to no longer be available through the link to mod, link, in the OP of this thread: http://www.simplemachines.org/community/index.php?topic=230676.2480

Can you tell me where it is now?

Quote from: Arantor on December 25, 2016, 03:55:57 AM
<meta property="og:url"               content="' . str_replace('https://', 'http://', $context['canonical_url'], 1) . '" />

Love your signature!!  ;)
Title: Re: Lost FB likes after moving to SSL
Post by: spiros on December 25, 2016, 05:40:32 AM
Thanks, Arantor :) I got this:

Fatal error: Only variables can be passed by reference in ...forum/Themes/citiez_20a/index.template.php on line 142
Title: Re: Lost FB likes after moving to SSL
Post by: Arantor on December 26, 2016, 01:54:41 AM
Take the ', 1' part off inside the str_replace call. I forgot that whereas with other functions, you can tell it to only replace one thing like this, str_replace will instead give you back the number of things it changed.

You shouldn't really have a situation where the canonical URL somehow contains a second https:// in it but I figured better safe than sorry...
Title: Re: Lost FB likes after moving to SSL
Post by: spiros on December 26, 2016, 04:15:15 AM
Thanks, Arantor, one more time that you help me, I cannot count the times really :)

Funnily enough, this method did not get the FB Likes back, if anyone is trying the same. Here is my Open Graph code in case it is helpful to anyone else:

<meta property="og:url" content="' . str_replace('https://', 'http://', $context['canonical_url']) . '" />
<meta property="og:type" content="website" />
<meta property="og:title" content="' . $context['page_title_html_safe'] . '" />
<meta property="og:description" content="' . $context['page_title_html_safe'] . '" />
<meta property="og:image" content="https://www.translatum.gr/forum/Themes/citiez_20a/images/translatumlogo.jpg" />
<meta property="og:image:width" content="250" />
<meta property="og:image:height" content="250" />
<meta property="fb:admins" content="100000773649123" />
<meta property="fb:app_id" content="133026706734105" />
<meta property="og:site_name" content="Translatum.gr />';


The Facebook debugger found as error a circular URL since I have htaccess redirects from http to https and the og:url is different from the canonical.

https://developers.facebook.com/tools/debug/
Title: Re: Lost FB likes after moving to SSL
Post by: Kindred on December 26, 2016, 08:15:50 AM
actually, I am somewhat confused as to why Facebook would not accept https...   given that most, if not everyone, will be going to https shortly (or face penalties from google, etc) and given that facebook has required https for apps and itself for well over a year now...


I use https for a wordpress blog site... and facebook pulls those share and even the preview image just fine...


so, I honestly don't think that https is your actual issue

Title: Re: Lost FB likes after moving to SSL
Post by: Arantor on December 26, 2016, 08:21:05 AM
No, different thing, Kindred.

FB likes are based off the URL, which is why canonical is important but it seems like they base it on the actual URL rather than the declared canonical.

This is just part of why I dislike Facebook.
Title: Re: Lost FB likes after moving to SSL
Post by: spiros on December 26, 2016, 09:00:43 AM
Quote from: Kindred on December 26, 2016, 08:15:50 AM
I use https for a wordpress blog site... and facebook pulls those share and even the preview image just fine...

Wordpress has the same issues when MOVING to SSL. Old likes are lost, there are hacks around: see

https://wordpress.org/support/topic/moved-to-https-likes-gone-can-i-specify-ogurl/
https://wordpress.org/support/topic/move-to-ssl-losing-likes/
Title: Re: Lost FB likes after moving to SSL
Post by: Kindred on December 26, 2016, 09:06:32 AM
oh, I see....  it's not that you can't like -- it's that FB, being coded by drunk monkeys, dones't think that https--blah is the same as http--blah

I seriously don't think there is any way around it for you...
Title: Re: Lost FB likes after moving to SSL
Post by: nend on December 26, 2016, 09:32:27 AM
Facebook isn't the only one. Google search console treats https and http as different sites. I still have half of my URLs on http in the console.

AFAIK, in the OG protocol, url is to be treated as the ID.
Quoteog:url - The canonical URL of your object that will be used as its permanent ID in the graph, e.g., "http://www.imdb.com/title/tt0117500/".

So the protocol clearly states to treat this string as the permanent ID. If Facebook followed their protocol to a T, then there is no fix.
Title: Re: Lost FB likes after moving to SSL
Post by: spiros on May 12, 2018, 06:34:19 AM
Seems that SMF does not like some of this code

8: Undefined index: canonical_url
...public_html/forum/Themes/citiez_20a/index.template.php
Line: 142


Line 142 has this:
<meta property="og:url" content="' . $context['canonical_url'] . '" />

Posted here about this:
https://www.simplemachines.org/community/index.php?topic=560302.0
Title: Re: Lost FB likes after moving to SSL
Post by: Kindred on May 12, 2018, 04:54:01 PM
As stated in the other thread....that error is due to some mistake in your custom coding, since that error does not occur in a baseline smf installation
Title: Re: Lost FB likes after moving to SSL
Post by: spiros on May 12, 2018, 05:17:06 PM
Well, not exactly my coding, I followed the suggestions in the thread I linked to. :)
Title: Re: Lost FB likes after moving to SSL
Post by: Aleksi "Lex" Kilpinen on May 13, 2018, 04:00:43 AM
The like count is just a number - if you have a redirection in place, you haven't lost anything except statistics. I wouldn't really worry about that myself.
But, I think you could do this with something like this for topics

<meta property="og:url" content="http://www.example.com/index.php?topic=', $context['current_topic'], '" />

Not a clean solution, but should work.
Title: Re: Lost FB likes after moving to SSL
Post by: spiros on May 13, 2018, 04:13:27 AM
Many thanks :)

I tried that and now I get:

8: Undefined index: current_topic
Line: 142
Title: Re: Lost FB likes after moving to SSL
Post by: Aleksi "Lex" Kilpinen on May 13, 2018, 04:15:00 AM
Where do you have it? Outside topics it will need an if statement and check that current_topic is actually set.

For example:
if (!empty($context['current_topic']))
Title: Re: Lost FB likes after moving to SSL
Post by: spiros on May 13, 2018, 04:33:41 AM
File posted here:

https://www.simplemachines.org/community/index.php?topic=560302.msg3972217#msg3972217

Search for:
<meta property="og:url" content="' . $context['canonical_url'] . '" />
Title: Re: Lost FB likes after moving to SSL
Post by: Aleksi "Lex" Kilpinen on May 13, 2018, 04:40:02 AM
Yeah, if it's in index.template.php it will need an if statement, because current_topic is only set when you are in a topic.
Title: Re: Lost FB likes after moving to SSL
Post by: spiros on May 13, 2018, 04:43:05 AM
What code do I need to use then? Sorry for being so inept :)

Edit, this appears to have solved it:

if (!empty($context['canonical_url']))
echo '
<meta property="og:url" content="' . $context['canonical_url'] . '" />
Title: Re: Lost FB likes after moving to SSL
Post by: Aleksi "Lex" Kilpinen on May 13, 2018, 11:55:31 AM
Yeah, actually that's even better :)