📜 ⬆️ ⬇️

1000 and 1 repost: a guide on the "share" button in Russian social networks



Recently, I faced a task - to hold on our site a “popular vote” for nominees for an award in our industry (franchising). As part of a popular vote, a person posted a post on his page on a social network, telling about who he voted for. To accomplish this task, I had to shovel a lot of information about how the sharing in various social networks is arranged, and how best to place these posts. In addition, a system was created for counting the number of posted reposts.

Unfortunately, most of the information on this topic, which can be found on Habré or stackoverflow, is already outdated, so I tried to turn this post into a current mega-guide for page sharing in social networks. I reviewed the 5 most popular social networks in Russia: contact, facebook, twitter, classmates and my world. For each social network, there is an up-to-date URL for sharing, small tips and recommendations for use, as well as JS code to find out the number of sheriras of a specific URL in each of the social networks. networks.
')
At the end of the article there is a summary table with all the links and a brief description of the capabilities of each of the networks.

Php script


Wrote a script generator links for sharinga, as well as to obtain data on the number of sherov.
Download here:
github.com/iskander-g/socialhelper

In contact with



The most popular social network in Russia also has the richest functionality for sharing, but there is also an annoying bug.

URL in order to share a link in this social. network has the following form:
http://vk.com/share.php?url={$url}&title={$titleVk}&description={$desc}&image={$image}&noparse=true 

Its parameters are:


Tips & Tricks:

You can add your hashtags to the end of the title, and if the user doesn’t enter a description when sharing, they will be posted to the user’s post.

Bugs :

Only one but very critical bug was found in the contact: if a user who is not authorized to contact passes through your link, he will be asked to login and then he will receive a white page with the words “too long to param”. The only way to solve this problem is not to transmit a description, etc., and limit it to a link only. Well, or just to score, as we did. This did not prevent at the moment to collect more than 900 reposts of our premium vkontakte.

Getting the number of sherov:

Getting the number of Sherov VKontakte is based on the fact that you add a script tag to your page with the following address:
 var index = "1"; //            -       . //  -   . var url = "http://example.com"; $("body").append("<script src='https://vk.com/share.php?act=count&index=" + index + "&url=" + url + "'></script>"); 

This script will call the VK.Share.count (index, count) method. Accordingly, you need to define it in the global scope, like this:
 var VK = {}; VK.Share = {}; VK.Share.count = function(index, count) { console.log(count); } 


Facebook



The second most popular social network in Russia has a rather curtailed tool for sharing links.

The URL to share the link on facebook is:
 https://www.facebook.com/sharer/sharer.php?u={$url}&picture={$image} 

As you can see, Facebook does not support the transfer of custom headers and descriptions - it takes this data from the page that is scrolling from the corresponding meta tags:


Tips & Tricks

Facebook does not support custom titles and descriptions for the link - in our case it was a problem, because we count the votes ourselves with an internal counting system, and we would like people to post a link to the page with all nominees in their social networks - so that their friends, going by reference, could immediately vote. Obviously, meta-tags with common texts and descriptions were set for this page, but we wanted the person to post information about who he specifically voted for when sharing.

This was achieved by creating “technical” pages for each nominee with the necessary meta tags that were successfully downloaded and parsed by Facebook, but when a regular user entered this page, it was automatically redirected to the nomination page (this was done using the refresh meta tag and duplicate javascript just in case).

Bugs

On the Internet, there is a lot of information about sharing on Facebook, and everywhere they write about this link:
 http://www.facebook.com/sharer/sharer.php?s=100&p%5Burl%5D= 

BUT! This link does not work with the mobile version of Facebook. You just need to use sharer/sharer.php?u=
sharer/sharer.php?u=


Counting the number of Facebook cheers

Facebook has the most difficulties in sharing, but it’s the easiest mechanism for recognizing the number of sherov for a particular URL.

It looks like this:
 $.get("https://graph.facebook.com/" + url, {}, function(data) { console.log(data.share.share_count); }, 'json'); 

Also on this link you can read the OG-parameters that are stored on Facebook, and some other properties of the URL.

Twitter



Twitter does not support posting images to links, or I have not found how to do it. Also, the post on Twitter is limited in length, so the description will not be sent there. But on Twitter you can transfer the login of your main account so that people subscribe to it too.

The Twitter URL looks like this:
 https://twitter.com/share?url={$url}&text={$title}&hashtags={$hashtags}&via={$account} 

Options:

Do not specify too long text and many hashtags! Tweet size is limited in length, and your user will be forced to edit your text.

Count the number of tweets

Counting the number of sheri of a specific url on Twitter using the methods of the social network itself is impossible.
twitter.com/twitterdev/status/667836799897591808

Classmates



At its core, sharing in classmates is completely analogous to sharing in facebook.

Url for sharing in classmates:
 https://connect.ok.ru/offer?url={$url} 

It is also impossible to transfer custom descriptions and stuff, you also have to use technical intermediate pages, all similar to Facebook.

Number of page cheers in classmates

But the process of counting the number of sherians in classmates is more like a contact - the JS script is also connected, which calls the ODKL.updateCount (rel, count) method.

The difference from the contact is that arbitrary text can be used as an index, not just an integer.

The code I use to count the sheriers is:
 var ODKL = {}; ODKL.updateCount = function(uid, count) { console.log(count); } var uid = "mainpage"; // UID -  index   var url = "http://example.com"; $.getJSON('https://connect.ok.ru/dk?st.cmd=extLike&uid=' + uid + '&ref=' + encodeURIComponent(url) + '&callback=?', function(e) {}); 


My world



In principle, the URL and the process of sharing in my world is similar to that in contact.

The link for my world is as follows:
 http://connect.mail.ru/share?url={$url}&title={$title}&description={$desc}&image_url={$image} 



Getting data on the number of sheri of my world

The ready code for getting the number of sherirs of a specific urla from my world looks like this:
  $.getJSON('https://connect.mail.ru/share_count?url_list=' + encodeURIComponent(url) + '&callback=1&func=?', function(response) { var url = encodeURIComponent(url); for (var url in response) { if (response.hasOwnProperty(url)) { var count = response[url].shares; console.log(count); } } }); 


Google


For information on Google, thank you Finesse
Link for sharing:
 https//plus.google.com/share?url={$url} 


There is no easy way to get the number of rassharivaniya in g +, but there are dirty, for example, parse from the answer to the address:
 https://apis.google.com/u/0/se/0/_/+1/sharebutton?plusShare=true&usegapi=1&action=share&url={$url} 


Summarizing


Soc. networkLinkCustom descriptionsCounterHashtags
In contact withhttp://vk.com/share.php?url={$url}&title={$titleVk}&description={$desc}&image={$image}&noparse=trueSupports for any pageThere isIn title
Facebookhttps://www.facebook.com/sharer/sharer.php?u={$url}&picture={$image}Only the picture, the rest through OGThere isAbsent
Twitterhttps://twitter.com/share?url={$url}&text={$title}&hashtags={$hashtags}&via={$account}Supports for any pageMissingRegular
Classmateshttps://connect.ok.ru/offer?url={$url}Using OG Meta TagsThere isAbsent
My worldhttp://connect.mail.ru/share?url={$url}&title={$title}&description={$desc}&image_url={$image}Supports for any pageThere isAbsent
Googlehttps//plus.google.com/share?url={$url}Using OG Meta TagsDirty wayAbsent


PS The optimal image size for sharing in social networks, which will look equally good everywhere - 1024x512 pixels.

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


All Articles