r - Creating a JSON file to use the RPushbullet package -
i discovered rpushbullet
bundle , have been unsuccessfully trying set use. the author's blog provides step step guide installation of package; however, encounter few issues. here first 2 steps:
the next step consists of inserting info in json file .rpushbullet.json
in home directory. had never used json file before read few articles on format. anyway, info set in json file is:
the reason 3rd step when rpushbullet
bundle loaded, attempts read json file in order obtain info in it.
i created file help of notepad++ , named .rpushbullet.json (which name required package) become json file (and windows identified one). (and first problem), when load package, file not found reason. here error message:
> library(rpushbullet) attaching rpushbullet version 0.1.1. no file ~/.rpushbullet.json found. consider placing pushbullet api key , device id(s) there.
the library not "see" json file created. error message suggests add together api key , device id file. author provides code generates json code re-create , paste in file:
> library(rjsonio) > cat(tojson(list(key="..your key here..", devices=c("..device a..", "..device b..")))) { "key": "..your key here..", "devices": [ "..device a..", "..device b.." ] }
as mentioned above, api key easy obtain because in business relationship settings page. device id, on other hand, not obtain pushbullet website. after research, learnt possible obtain device id within r
jsonlite
package. here code , ensuing error message:
> fromjson(pbgetdevices())$devices[,c("iden", "nickname")] error in fromjson(pbgetdevices()) : error in evaluating argument 'content' in selecting method function 'fromjson': error: neither alternative 'rpushbullet.key' nor entry in bundle environment found. aborting
apparently, json file created in home directory not "seen" package.
i need help, please.
first, if says cannot find .rpushbullet.json
file, saving it? should within whichever directory returned sys.getenv("home")
(e.g., /home/username
, /users/username
, ...)
as i'm playing it, appears api returning has changed ever-so-slightly, because rjsonio::fromjson()
no longer interpreting same. (this might bug?) there several ways i've found cut down homecoming properly. i'll mimic pbgetdevices()
, mention diverge:
apikey <- "a1...98" ## replace string of api key txt <- sprintf("%s -s %s -u %s:", rpushbullet:::.getcurl(), "https://api.pushbullet.com/v2/devices", apikey) jsonres <- system(txt, intern = true) ## res <- fromjson(jsonres) ## doesn't work anymore res <- reduce(rbind, rjsonio::fromjson(jsonres)$devices)[,c('iden','nickname')]
the variable res
has data.frame 2 columns, device ids need, , nicknames show (as save them .rpushbullet.json
file) which.
(oh, ensure notepad++ not secretly appending .txt
filename. mutual windows thing, helping "protect" debilitating inconvenience of beingness exposed file extensions.)
json r package
No comments:
Post a Comment