MyNixOS website logo
Description

Access to VK API via R.

Provides an interface to the VK API <https://vk.com/dev/methods>. VK <https://vk.com/> is the largest European online social networking service, based in Russia.

Travis-CI Build Status CRAN_Status_Badge

vkR is an R package which provides access to the VKontakte (VK) API.

Installation

To get the current released version from CRAN:

install.packages("vkR")

To get the current development version from github:

install.packages("devtools")
devtools::install_github("Dementiy/vkR")
library("vkR")

Authorization

Most API requests require the use of an access token. VK has several types of authorization mechanisms. Check out the documentation for more details.

vkOAuth(CLIENT_ID, 'SCOPE', 'EMAIL', 'PASSWORD')

where:

  • CLIENT_ID - is an application ID. You have to create new Standalone-app in VK to get ID (or use the already existing).
  • SCOPE - the list of comma separated access rights, e.g. 'friends,groups'- provide the access to user friends and groups. List of all rights can be found here.
  • EMAIL and PASSWORD - username and password.

If the EMAIL and PASSWORD have been omitted, a browser window will be opened. In the address bar an access token will be shown. Access token must be copied and passed as an argument into the following function:

setAccessToken(access_token = 'YOUR ACCESS TOKEN')

Example of use

At your own risk you can use mongodb and mongolite package for storing data:

> db_init()
> wall <- getWallExecute(domain="data_mining_in_action", count=0, use_db=TRUE, progress_bar=TRUE)
|======================...======================| 100%
> show_collections()
    db            collection       suffix count
1 temp data_mining_in_action         wall   232

If connection was aborted by some reasons we don't lose our data:

> wall <- getWallExecute(domain='privivkanet', count=0, use_db = T, progress_bar = T)
|=================                              |  25%
Show Traceback
 
 Rerun with Debug
 Error in curl::curl_fetch_memory(url, handle = handle) : 
  Operation was aborted by an application callback ...
> show_collections()
    db            collection       suffix count
1 temp data_mining_in_action         wall   232
2 temp           privivkanet         wall   916
> wall <- getWallExecute(domain='privivkanet', count=0, offset=916, use_db = T, progress_bar = T)
|======================...======================| 100%
> show_collections()
    db            collection       suffix count
1 temp data_mining_in_action         wall   232
2 temp           privivkanet         wall  3664

You can specify the collection name:

> wall <- getWallExecute(domain="data_mining_in_action", count=0, 
        use_db=TRUE, db_params=list('collection'='dm', 'suffix'='posts'), progress_bar=TRUE)
|======================...======================| 100%
> show_collections()
    db            collection       suffix count
1 temp data_mining_in_action         wall   232
2 temp           privivkanet         wall  3664
3 temp                    dm        posts   232

> friends <- getFriends()
> users <- getUsersExecute(friends$items, use_db = TRUE, db_params=list('collection'='my_friends'), progress_bar = TRUE)
> show_collections()
    db            collection       suffix count
1 temp data_mining_in_action         wall   232
2 temp           privivkanet         wall  3664
3 temp                    dm        posts   232
4 temp            my_friends                141

For load collection into a namespace you can use db_load_collection function:

> db_load_collection('data_mining_in_action', 'wall')
 Imported 232 records. Simplifying into dataframe...
> ls()
[1] "temp.data_mining_in_action.wall"
> nrow(temp.data_mining_in_action.wall)
[1] 232

Building a Friend Graph:

my_friends <- getFriends(fields = 'sex')
my_friends <- filter(my_friends$items, is.na(deactivated))
network <- getNetwork(my_friends$id)

library("igraph")
g <- graph.adjacency(as.matrix(network), weighted = T, mode = "undirected")
layout <- layout.fruchterman.reingold(g)
plot(g, layout = layout)

Analyzing community activity:

domain <- 'nipponkoku'
wall <- getWallExecute(domain = domain, count = 0, progress_bar = TRUE)
metrics <- jsonlite::flatten(wall$posts[c("date", "likes", "comments", "reposts")])
metrics$date <- as.POSIXct(metrics$date, origin="1970-01-01", tz='Europe/Moscow')

library(dplyr)
df <- metrics %>% 
  mutate(period = as.Date(cut(date, breaks='month'))) %>% 
  group_by(period) %>%
  summarise(likes = sum(likes.count), comments = sum(comments.count), reposts = sum(reposts.count), n = n())

library(ggplot2)
library(tidyr)
ggplot(data=gather(df, 'type', 'count', 2:5), aes(period, count)) + geom_line(aes(colour=type)) +
  labs(x='Date', y='Count')

You can find more examples in examples directory.

Metadata

Version

0.2

License

Unknown

Platforms (75)

    Darwin
    FreeBSD 13
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd13
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd13
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows