问题描述
我的问题与此问题密切相关:LinkedIn API error of redirect uri from httr
这是我的代码:
random.choice
当我这样做时,浏览器将打开并显示消息library(httr)
clientid <- "MY-ID"
secret <- "MY-SECRET"
app <- oauth_app(appname = "app name",key = clientid,secret = secret)
endpoint <- oauth_endpoint(base_url = "https://www.linkedin.com/uas/oauth2",authorize = "authorization",access = "accesstoken")
token <- oauth2.0_token(endpoint = endpoint,app = app)
在R中,我得到这个:
Authentication complete. Please close this page and return to R.
我使用了https://www.linkedin.com/developers/上给我的应用程序提供的客户端ID和密码,并且确实将重定向URL设置为Waiting for authentication in browser...
Press Esc/Ctrl + C to abort
Authentication complete.
Error in oauth2.0_access_token(endpoint,app,code = code,user_params = user_params,:
Bad Request (HTTP 400). Failed to get an access token.
。
我正在使用Ubuntu 18.04,R版本3.6.3,httr版本“ 1.4.2”。
解决方法
我认为您可能缺少scope
中的oauth2.0_token()
参数。
您可以使用的LinkedIn范围示例为:scope = "r_organization_social"
或scope = "rw_organization_admin"
。
因此它看起来像:
token <- oauth2.0_token(endpoint = endpoint,app = app,scope = "rw_organization_admin")
这取决于您拥有多少访问权限以及您希望通过API请求哪些数据
,我解决了更改 :token