gpt4 book ai didi

r - 从 R 访问 bitly OAuth2 API

转载 作者:行者123 更新时间:2023-12-04 10:08:08 25 4
gpt4 key购买 nike

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

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

最佳答案

这是一种使用httr 的方法——它在packages' examples on GitHub 的脉络中:

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"

关于r - 从 R 访问 bitly OAuth2 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11493425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com