📜 ⬆️ ⬇️

New Mail.Ru API Features

New Mail.Ru API Features
After extensive testing, we launched a whole bunch of innovations in Mail.Ru API for social applications and external sites.


JS API and Flash API

Now you can make calls to the API directly from the client side of your applications in My World and on external sites. For this you need to connect and use the JS API.

Especially for flash-applications, we developed the Flash API, which makes it easy and convenient to use all the extensive features of the client JS API.
')



New features for applications and sites

Together with the advent of client APIs, we have the opportunity to implement many very useful functions, which we did not hesitate to use.

Application Installation Request
Now you can simply call the mailru.app.users.requireInstallation method in the client part of the application and say what settings (privileges) you want to receive from the user. As a result of the method call, the user will be shown the standard application installation dialog with the settings you have requested:

Application installation

Inviting friends
The same with invitations. Now you yourself can, at the right moment, raise the window of inviting friends to the application using the function mailru.app.friends.invite

Request Settings or Privileges
If you need some kind of setting that the user has not provided - you can raise the dialog for requesting this privilege using the function mailru.common.users.requirePremission and find out the result of the user's choice - whether he provided the requested privilege or not.

Record in the Guest Book
This is a new powerful tool for viral application distribution. With the help of the guestbook entry you can tell about your application not only to the friends of the current user, but also to any other users of My World, regardless of whether they have the application installed or not.

A guest book is a personal user space into which all users of My World can write, unless the owner of the Book has forbidden it. The guest book is displayed in the user profile under the “What's New” activity tape: Guest book

You can invoke the Guest Book entry dialog using the mailru.common.guestbook.publish function .

As parameters, you can pass the user ID to which the record will be added, the title of the record, a description, a picture and up to two action links leading to the application page. Through these links, you can pass an arbitrary set of parameters, which allows you to implement any business logic for processing users coming through these links.

Record in the activity tape What's New
A new method in the JS API mailru.common.stream.publish , which is designed to replace the server call from the stream.publish REST API.

The new method has several significant advantages: images for the record are downloaded from your server on the fly, you can specify several action links for the record, the records can be marked as liked and spread deep into the social graph.

Activity Tape Dialog

We recommend actively switching to the use of the new method of recording into the Whats New activity tape, as it is more effective for application developers and solves the problem of low-quality content for the Platform. Since the announcement, the server call stream.publish is declared obsolete and in the future its support for web applications and sites may be terminated, which we will warn in advance.

Raising the payment window
For billing, we also prepared a pleasant update - the new mailru.app.payments.showDialog method, called from the client side of the application, allows us to reduce the delay between calling and displaying the payment dialog, as well as programmatically track the progress of the payment. The dialogue itself is as follows:

Payment dialog

Now you can quickly, beautifully and elegantly notify the user about the accrual of purchased gold or the provision of a paid service. In a word, highly recommended for usage, because it will increase your income!

Create a photo album
Want to create a user photo album for your application? Or a few? Not a problem, with the new function mailru.common.photos.createAlbum you have the opportunity.

Saving photos in a user's album
Previously, developers could not add photos to the user's album, but now they can - using the mailru.common.photos.upload function. The perfect way for numerous avatar enhancement apps.

More information about the use of new features can be found in the documentation: JS API , Flash API .


An example of the simplest application

In fact, you can start using new features quickly and easily. The simplest iframe application might look something like this:
 <html>
 <head>
     <script type = "text / javascript" src = "http://connect.mail.ru/js/loader.js"> </ script>
 </ head>
 <body>

 <div id = "sandbox">
     <button id = "inviteFrineds" type = "button" onclick = "invite ();"> Invite friends </ button>
     <button id = "stream" type = "button" onclick = "stream ();"> Add an entry to "What's New" </ button>
 </ div>


 <script type = "text / javascript">
     mailru.loader.require ('api', function () {
         mailru.app.init ('your private key from application settings');
         // everything is ready, here you can work with API functions

         // check if the user has the application installed
         if (mailru.session.is_app_user! = 1) {
             // if not installed - call the installation dialog with permission to host the widget
             mailru.app.users.requireInstallation (['widget']);
             return false;
         }
     });


     function invite () {
         mailru.app.friends.invite ();
         return false;
     }

     function stream () {
         mailru.common.stream.publish ({
             'title': 'Title',
             'text': 'Text',
             'img_url': 'http://bitman.me/mailru/demo/img/stream_pic.jpeg',
             'action_links': [
                 {
                     'text': 'action link',
                     'href': document.location.host + '# link1'
                 }
             ]
         });
         return false;
     }
 </ script>
 </ body>
 </ html>


A more complete example is on github , there is also an example of using the library on an external site.

You can create an application or register a site for experiments on the developer portal api.mail.ru


P.S

I would like to say a special thank you to all the developers who took an active part in testing new features - without your help, this release would have happened later and would have turned out to be much less quality.

If habrasoobshchestva have an interest in the topic of social applications and the integration of social APIs on sites, then we can organize an online conference in Habré, where I and other members of our team will answer any questions posed by habrausers. Write in the comments how interesting it is to you.

For bananas, contact app@corp.mail.ru

I tried for you Alexey Terekhov from the team Platform@Mail.Ru

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


All Articles