Setting Google + Share Text (snippet)

I am creating an HTML5 / Javascript online test. I share the results of the Quiz via Facebook and Twitter. Messaging is created through Javascript: "I just got X of Y questions correctly"

I want to do the same with Google Plus. However, the “snippet” seems to be generated by the schema.org, Open Graph, or Title / Description tags on the page. Documentation here: https://developers.google.com/+/plugins/snippet/

I thought I could just dynamically generate these tags via query string parameters in PHP, but it looks like Google is caching the page. Any ideas?

PHP:

<?php $correct = strval($_GET['correct']); $title = "I took the Quiz and answered " . $correct . " of 9 questions correctly."; ?> <!DOCTYPE html> <html> <head> <title><?php echo($title); ?></title> <meta property="og:title" content="<?php echo($title); ?>" /> </head> </html> 

Am I dynamically creating url ... / share.php? correct = 4

But when I share the page, I see a message:

 I took the Quiz and answered of 9 questions correctly. 

It does not display dynamic data. I assume Google cached the page?

thanks

+4
source share
2 answers

The +1 button and sharing buttons use caching in the dialog box. It is assumed that the fragment collector will respect cache management directives, so you can implement what you are going to by providing the necessary headers to prevent caching.

In PHP, the following code sets headers with the necessary data to prevent caching:

 <?php header("Last-Modified: " . gmdate("D, d MYH:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); ?> 

Something else you could think and do is to insert a randomly generated identifier into the query string parameter so that the sharing URL looks unique to the recipient each time.

Hope this helps.

+3
source

As far as I know, plus one button caches pages. Same as the fb button. You can try this.

 https://plus.google.com/share?url=http://example.com/share.php?correct=4 

This is a trick. Hope this helps

+3
source

Source: https://habr.com/ru/post/1442153/


All Articles