我正在尝试运行一个调用 Linkedin API 的 groovy 脚本。问题是,如何使用 groovy 脚本中的 grails oauth 插件进行身份验证?这是我的配置:
oauth {
linkedin {
requestTokenUrl="https://api.linkedin.com/uas/oauth/requestToken"
accessTokenUrl="https://api.linkedin.com/uas/oauth/accessToken"
authUrl="https://www.linkedin.com/uas/oauth/authenticate"
consumer.key="xxxxxxxxx"
consumer.secret="xxxxxxxxxx"
}
}
这是我的脚本,我以 "grails run-script scriptname.groovy" 开头:
import org.grails.plugins.oauth.OauthService
def oauthService = new OauthService()
oauthService.reset()
def URL = "http://api.linkedin.com/v1/people-search?country-code=us&postal-code=98102&distance=100&start=0&count=5"
def recs_response = oauthService.accessResource( URL, "linkedin", [key:"xxxxxxx", secret:"xxxxxxxxx"], 'GET')
println "it worked"
如果我打印响应,我会得到“OAuth 请求中使用的令牌无效”
谢谢。