S
S
slip352017-03-23 20:33:47
API
slip35, 2017-03-23 20:33:47

Auto-renewal of a token in the Yandex Metrics API?

Using the Yandex Metrics API, you can display dynamic information with site statistics on the site.
In general, this is not difficult to do, and the Internet is full of material that helps to solve this problem. The bottom line is that you need to create a Yandex application, get a token and place the appropriate code for collecting and displaying statistics on the site.
Yes, it works.
But as far as I could figure out, there is one important point in this scheme - the token itself. Without it, accordingly, nothing will work. And here's the annoyance, it turns out that the token has a lifetime (maximum 1 year).
So, for some reason, in their manuals, no one focuses on the renewal of the token. The statistics seemed to have been taken out and beautifully designed. But, for example, in a year EVERYTHING WILL DISAPPEAR, and therefore such a thing does not belong to the category "done and forgot" .
I'm interested to know how to implement automatic token renewal process in PHP code? Maybe someone faced this problem?
PS Somewhere a long time ago, a link was thrown on a toaster in the relevant topic, they say, look how cool such live statistics are implemented on the site. Here is someone who did it using the same manuals with the "dying" token. And now, probably, he doesn’t even realize that his page is dead!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis A., 2017-06-30
@myphpscript

Too late, of course, but: Send POST
to https://oauth.yandex.ru/token

{
  refresh_token: '<refresh_token, полученный при первой авторизации>',
  client_id: '<ID вашего приложения в Яндекс>',
  client_secret: '<Ключ приложения>',
  grant_type: 'refresh_token'
}

The response is JSON with new access_token and refresh_token.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question