3

我希望能够从 R 访问bitly OAuth2 api,并且想知道是否有任何示例实现,或者更好的是,围绕 bitly API 的 R 库/包装器?

twitteR 库跨越了一个R OAuth 库 ROAuth,但这大概不支持 OAuth2?或者 OAuth2 会接受 OAuth1 提议吗?

4

3 回答 3

2

这是一种使用方式- 它在 GitHub 上httr的包示例的脉络中:

require(jsonlite)
require(httr)

# 1. Find OAuth settings for bit.ly:
# http://dev.bitly.com/authentication.html
bitly <- oauth_endpoint(
  authorize = "https://bitly.com/oauth/authorize",
  access = "https://api-ssl.bitly.com/oauth/access_token")

# 2. Register an application at http://dev.bitly.com/my_apps.html
# Insert your values below - if secret is omitted, it will look it up in
# the BITLY_CONSUMER_SECRET environmental variable.
myapp <- oauth_app("bitly", 
                   key = ".............................", # Client ID
                   secret = "............................") # Client Secret

bitly_token <- oauth2.0_token(bitly, myapp, cache = FALSE) 

# 4. Use API
req <- GET("https://api-ssl.bit.ly/v3/user/info", query = list(access_token = bitly_token$credentials$access_token))
stop_for_status(req)
content(req)$data$profile_url
# [1] "http://bitly.com/u/lukeanker"
于 2014-08-28T14:47:03.557 回答
1

到目前为止,我已经在一个与其他 API 相关的包中编写了三个 fxns:https ://github.com/ropensci/raltmet/tree/master/R

三个fxns根据用户获取clickc,展开url和缩短url

通过以下方式安装:

install.packages("devtools")
require(devtools)
install_github("raltmet", "ropensci")
require(raltmet)
于 2012-07-15T16:17:07.057 回答
0

可以使用尚未更新的 CRAN 版本的 ROAUth ( ROAuth 0.92) 来完成此操作。我在这里有一份工作副本。ROAuth从此源安装后,下载一份副本RMendeley以测试 R 如何与 oauth 配合使用。

library(devtools)
install_github("rmendeley", "ropensci")
于 2012-07-15T17:24:40.370 回答