HTTP状态401 Semantria API

时间:2019-06-06 08:35:16

标签: r http-status-code-401 httr

阅读API指南后,我期待使用R中的httr包进行请求。

作为一个简单的测试,我希望通过语言获得功能,这应该是一个相对容易的调用。但是,即使我根据指南正确构建了URL,也未能成功。

通话网址为:

https://api.semantria.com/features.json?oauth_consumer_key=25459811-a9cd-3020-8afd-f7e16400653a&oauth_nonce=55Li4Bfa4h&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1559806878&oauth_version=1.0&language=en

本示例中的

密钥和随机数已被修改!

身份验证方法为oauth_signature

https://semantria.readme.io/v4.2.3/reference#authentication https://semantria.readme.io/v4.2.3/reference#checking-supported-features-by-language

library(httr)

oauth_url <- "https://api.semantria.com"

semantria <- oauth_app(appname = "semantria",
                       key = consumerKey,
                       secret = consumerSecret)

signature <- oauth_signature(url = oauth_url, 
                            method = "GET", 
                            app = semantria,
                            token = consumerKey,
                            token_secret = consumerSecret)

url <- modify_url(url = url,
           path = "/features.json",
           query = list(
             oauth_consumer_key = oauth_consumer_key,
             oauth_nonce = oauth_nonce,
             oauth_signature_method = oauth_signature_method,
             oauth_timestamp = oauth_timestamp,
             oauth_version = oauth_version,
             language = "en"
           ))

response <- GET(url)

0 个答案:

没有答案