我想从Withings Api获取用户信息,我已经成功地使用Scribe库(Java)以Oauth登录Withings。但是,当我发送请求获取用户信息后跟Withings Api文档时,总是返回带有错误代码的结果,这时会出现问题。如何从Withings api获取用户信息grails
我试过一些方法,但没有奏效。有人可以帮助我解决这个问题。
Withings阿比http://www.withings.com/en/api#documentation
首先我打电话withings行动WithingsController.groovy得到验证。
验证成功服务器返回访问令牌后,在withingsCallback操作中,我获取用户信息。
时获取用户信息是Withings的API结果代码的结果返回
{ “地位”:2554}
这是我的代码
WithingsService.groovy
def getAuthDetails(callbackUrl) {
if (!authService) {
authService = new ServiceBuilder()
.provider(WithingsApi.class)
.apiKey(grailsApplication.config.oauth.withings.key as String)
.apiSecret(grailsApplication.config.oauth.withings.secret as String)
.callback(callbackUrl as String)
.build();
}
Token requestToken = authService.getRequestToken();
[ authUrl : authService.getAuthorizationUrl(requestToken), requestToken : requestToken ]
}
def getWithingsUserInformation(Token accessToken,String userId){
String url = 'http://wbsapi.withings.net/user?action=getbyuserid&userid='+userId;
OAuthRequest request = new OAuthRequest(Verb.POST, url)
authService.signRequest(accessToken, request)
Response response = request.send()
return response
}
def getAccessToken(params, requestToken){
requestToken = requestToken as Token
Verifier verifier = new Verifier(params.oauth_verifier)
authService.getAccessToken(requestToken, verifier);
}
WithingsController.groovy
def withings() {
def authInfo = withingsService.getAuthDetails(createLink(action: 'withingsCallback', controller: 'withings', absolute: 'true'))
if (authInfo.requestToken)
{
session["withings_requestToken"] = authInfo.requestToken
}
}
def withingsCallback(){
def accessToken = withingsService.getAccessToken(params, session["withings_requestToken"])
session["withings_accessToken"] = accessToken
if(accessToken) {
def profile
String userId = params.userid
profile = withingsService.getWithingsUserInformation(accessToken,userId)
}
}
您能告诉我们更多信息吗?在典型的Oauth流程中,您1)获得auth url 2)将用户重定向到auth url 3)用户通过accesstoken认证和提供者调用您的服务器回调4)您使用访问令牌。您能否向我们展示#3,更具体地说,您在回调中所做的事情,最后得到的错误是什么。 – ikumen
我已经添加了更多细节。希望你能帮助我解决这个问题 – user2476726