开发者

OAuth access for R

开发者 https://www.devze.com 2023-01-09 18:21 出处:网络
I\'m trying to use R to grab some web data that requires OAuth authentication. Searching on CRAN and RSeek.org for info on OAuth + R provides nothing. Any tips开发者_开发百科 for accessing RESTful API

I'm trying to use R to grab some web data that requires OAuth authentication. Searching on CRAN and RSeek.org for info on OAuth + R provides nothing. Any tips开发者_开发百科 for accessing RESTful APIs with R using OAuth?

I'm considering using some Python/Perl/Ruby to grab the data, save it to a text file, then work on it with R. I'd prefer to stay totally in R, but it seems like OAuth is a barrier.


Turns out Jeff Gentry from TwitteR wrote his own OAuth R library.

http://cran.r-project.org/web/packages/ROAuth/index.html


Best approach now appears to be to use httr (https://github.com/r-lib/httr)


One option I stumbled on is called OAuth Proxy and it slips the OAuth headers in using a proxy. This is an interesting kludge.


Another possible, assuming you have access to the required crypto functions in R, you can implement OAuth completely as HTTP requests without any lib support etc.

While writing a complete oauth lib might be asking too much, if you just need a quick and dirty way to pull down data, it shouldn't be too difficult to hand craft the few functions you need to complete an oauth request.

Also, while R may not have an oauth lib, most of the difficult part of oauth is in the interaction between servers, not in creating the tokens/requests, so you should be able to look at another language's implementation and port the required logic to R. I would suggest looking at a simple lib from http://oauth.net/code/ for a starting point.


It's possible to do this with the RCurl library as well. The main thing is that you parse the access_tokens and authorization verifications correctly. But I've managed to pull lots of data off of facebook with R via getURL.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号