我正在使用restfb java sdk在我的应用中添加facebook登录 我已经创建了一个测试应用程序,但当我尝试获取用户的详细信息后显示错误消息
[FacebookOAuthException: Received Facebook error response of type OAuthException: An active access token must be used to query information about the current user. (code 2500, subcode null)]
这是我的代码
val config = ConfigFactory.load()
val FBAppId = config.getString("fb.app.id")
val FBAppSecret = config.getString("fb.app.secretkey")
val aceessToken = new DefaultFacebookClient().obtainAppAccessToken(FBAppId, FBAppSecret)
log.info("token is "+aceessToken.getAccessToken)
val facebookClient = new DefaultFacebookClient(aceessToken.getAccessToken)
val fbuser = facebookClient.fetchObject("me",classOf[User] ,Parameter.`with`("fields", "id,name,email, first_name , last_name"))
log.info("name : {} ", fbuser.getName)
log.info("User first name :{} ", fbuser.getFirstName)
log.info("User last name : {}" , fbuser.getLastName)
log.info("User Email : {}" , fbuser.getEmail)
这是在控制台上打印的访问令牌
token is 587299244766256|udH5HgYve1DHGjKHU55hBw9Ik5Y
(我认为这是不正确的,因为我在Facebook文档中读到访问令牌由150个字符组成,并且生成的令牌不是150个字符长) 在这一行
val fbuser = facebookClient.fetchObject("me",classOf[User] ,Parameter.`with`("fields", "id,name,email, first_name , last_name"))
抛出异常
[FacebookOAuthException: Received Facebook error response of type OAuthException: An active access token must be used to query information about the current user. (code 2500, subcode null)]
请帮助我如何获取登录用户的详细信息
答案 0 :(得分:0)
您无法使用应用访问令牌获取端点me
。您需要用户或页面访问令牌。