Imports System.Net
Imports Newtonsoft.Json
Public Class YandexBilgileri
Public Property oauth_token As String
Public Property id As String
End Class
Public Class YandexMetrika
Private Shared Function getJsonString(url As String) As String
Dim wc As New WebClient()
Dim rs As String = wc.DownloadString(url)
wc.Dispose()
wc = Nothing
Return rs
End Function
Public Shared Function getBirHaftalikZiyaretci(bilgiler As YandexBilgileri) As Yandex.Ziyaretler.RootObject
Dim rs As String = getJsonString(String.Format("https://api-metrika.yandex.com.tr/stat/traffic/summary.json?id={0}&oauth_token={1}", bilgiler.id, bilgiler.oauth_token))
Dim DetaylarRoot As Yandex.Ziyaretler.RootObject = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Yandex.Ziyaretler.RootObject)(rs)
Return DetaylarRoot
End Function
Public Function getBugunArananKelimeler(bilgiler As YandexBilgileri) As Yandex.ArananKelimeler.RootObject
Dim rs As String = getJsonString(String.Format("https://api-metrika.yandex.com.tr/stat/sources/phrases?id={3}&oauth_token={4}&date1={0}{1}{2}&date2={0}{1}{2}", Now.Year, Now.Month, Now.Day, bilgiler.id, bilgiler.oauth_token))
Dim DetaylarRoot As Yandex.ArananKelimeler.RootObject = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Yandex.ArananKelimeler.RootObject)(rs)
Return DetaylarRoot
End Function
End Class
Namespace Yandex.ArananKelimeler
Public Class SearchEngine
Public Property se_id() As Integer
Get
Return m_se_id
End Get
Set
m_se_id = Value
End Set
End Property
Private m_se_id As Integer
Public Property se_page() As Integer
Get
Return m_se_page
End Get
Set
m_se_page = Value
End Set
End Property
Private m_se_page As Integer
Public Property se_url() As String
Get
Return m_se_url
End Get
Set
m_se_url = Value
End Set
End Property
Private m_se_url As String
End Class
Public Class Datum
Public Property denial() As Double
Get
Return m_denial
End Get
Set
m_denial = Value
End Set
End Property
Private m_denial As Double
Public Property visits() As Integer
Get
Return m_visits
End Get
Set
m_visits = Value
End Set
End Property
Private m_visits As Integer
Public Property depth() As Double
Get
Return m_depth
End Get
Set
m_depth = Value
End Set
End Property
Private m_depth As Double
Public Property page_views() As Integer
Get
Return m_page_views
End Get
Set
m_page_views = Value
End Set
End Property
Private m_page_views As Integer
Public Property phrase() As String
Get
Return m_phrase
End Get
Set
m_phrase = Value
End Set
End Property
Private m_phrase As String
Public Property visit_time() As Integer
Get
Return m_visit_time
End Get
Set
m_visit_time = Value
End Set
End Property
Private m_visit_time As Integer
Public Property id() As String
Get
Return m_id
End Get
Set
m_id = Value
End Set
End Property
Private m_id As String
Public Property search_engines() As List(Of SearchEngine)
Get
Return m_search_engines
End Get
Set
m_search_engines = Value
End Set
End Property
Private m_search_engines As List(Of SearchEngine)
End Class
Public Class Totals
Public Property denial() As Double
Get
Return m_denial
End Get
Set
m_denial = Value
End Set
End Property
Private m_denial As Double
Public Property visits() As Integer
Get
Return m_visits
End Get
Set
m_visits = Value
End Set
End Property
Private m_visits As Integer
Public Property depth() As Double
Get
Return m_depth
End Get
Set
m_depth = Value
End Set
End Property
Private m_depth As Double
Public Property page_views() As Integer
Get
Return m_page_views
End Get
Set
m_page_views = Value
End Set
End Property
Private m_page_views As Integer
Public Property visit_time() As Integer
Get
Return m_visit_time
End Get
Set
m_visit_time = Value
End Set
End Property
Private m_visit_time As Integer
End Class
Public Class RootObject
Public Property date1() As String
Get
Return m_date1
End Get
Set
m_date1 = Value
End Set
End Property
Private m_date1 As String
Public Property date2() As String
Get
Return m_date2
End Get
Set
m_date2 = Value
End Set
End Property
Private m_date2 As String
Public Property id() As Integer
Get
Return m_id
End Get
Set
m_id = Value
End Set
End Property
Private m_id As Integer
Public Property rows() As Integer
Get
Return m_rows
End Get
Set
m_rows = Value
End Set
End Property
Private m_rows As Integer
Public Property data() As List(Of Datum)
Get
Return m_data
End Get
Set
m_data = Value
End Set
End Property
Private m_data As List(Of Datum)
Public Property totals() As Totals
Get
Return m_totals
End Get
Set
m_totals = Value
End Set
End Property
Private m_totals As Totals
End Class
End Namespace
Namespace Yandex.Ziyaretler
Public Class Datum
Public Property denial() As Double
Get
Return m_denial
End Get
Set
m_denial = Value
End Set
End Property
Private m_denial As Double
Public Property [date]() As String
Get
Return m_date
End Get
Set
m_date = Value
End Set
End Property
Private m_date As String
Public Property visits() As Integer
Get
Return m_visits
End Get
Set
m_visits = Value
End Set
End Property
Private m_visits As Integer
Public Property visitors() As Integer
Get
Return m_visitors
End Get
Set
m_visitors = Value
End Set
End Property
Private m_visitors As Integer
Public Property depth() As Double
Get
Return m_depth
End Get
Set
m_depth = Value
End Set
End Property
Private m_depth As Double
Public Property page_views() As Integer
Get
Return m_page_views
End Get
Set
m_page_views = Value
End Set
End Property
Private m_page_views As Integer
Public Property visit_time() As Integer
Get
Return m_visit_time
End Get
Set
m_visit_time = Value
End Set
End Property
Private m_visit_time As Integer
Public Property new_visitors() As Integer
Get
Return m_new_visitors
End Get
Set
m_new_visitors = Value
End Set
End Property
Private m_new_visitors As Integer
Public Property id() As String
Get
Return m_id
End Get
Set
m_id = Value
End Set
End Property
Private m_id As String
End Class
Public Class Totals
Public Property denial() As Double
Get
Return m_denial
End Get
Set
m_denial = Value
End Set
End Property
Private m_denial As Double
Public Property visits() As Integer
Get
Return m_visits
End Get
Set
m_visits = Value
End Set
End Property
Private m_visits As Integer
Public Property visitors() As Integer
Get
Return m_visitors
End Get
Set
m_visitors = Value
End Set
End Property
Private m_visitors As Integer
Public Property depth() As Double
Get
Return m_depth
End Get
Set
m_depth = Value
End Set
End Property
Private m_depth As Double
Public Property page_views() As Integer
Get
Return m_page_views
End Get
Set
m_page_views = Value
End Set
End Property
Private m_page_views As Integer
Public Property visit_time() As Integer
Get
Return m_visit_time
End Get
Set
m_visit_time = Value
End Set
End Property
Private m_visit_time As Integer
Public Property new_visitors() As Integer
Get
Return m_new_visitors
End Get
Set
m_new_visitors = Value
End Set
End Property
Private m_new_visitors As Integer
End Class
Public Class RootObject
Public Property date1() As String
Get
Return m_date1
End Get
Set
m_date1 = Value
End Set
End Property
Private m_date1 As String
Public Property date2() As String
Get
Return m_date2
End Get
Set
m_date2 = Value
End Set
End Property
Private m_date2 As String
Public Property id() As Integer
Get
Return m_id
End Get
Set
m_id = Value
End Set
End Property
Private m_id As Integer
Public Property rows() As Integer
Get
Return m_rows
End Get
Set
m_rows = Value
End Set
End Property
Private m_rows As Integer
Public Property data() As List(Of Datum)
Get
Return m_data
End Get
Set
m_data = Value
End Set
End Property
Private m_data As List(Of Datum)
Public Property totals() As Totals
Get
Return m_totals
End Get
Set
m_totals = Value
End Set
End Property
Private m_totals As Totals
End Class
End NamespaceKullanım :
Dim TekilZiyaretci As String
Dim SayfaGosterim As String
Dim yBilgileri As New YandexBilgileri
yBilgileri.id = "metrica id si"
yBilgileri.oauth_token = "yandex oauth kodu"
Dim haftalikBilgileri = YandexMetrika.getBirHaftalikZiyaretci(yBilgileri)
Dim liste = haftalikBilgileri.data
For Each a In liste
TekilZiyaretci &= String.Format("{0},", a.visits)
SayfaGosterim &= String.Format("{0},", a.page_views)
NextKaynak sınıfı ve kullanım örnektir
https://tech.yandex.com.tr/metrika/d...pular-docpage/
adresinde örnek sorgu çeşitleri var, verdiğim sınıfı geliştirebilirsiniz veya kendiniz bir sınıf oluşturabilirsiniz.