Skip to content

Instantly share code, notes, and snippets.

@pj
Last active August 29, 2015 14:07
Show Gist options
  • Save pj/3904d708ad1242386760 to your computer and use it in GitHub Desktop.
Save pj/3904d708ad1242386760 to your computer and use it in GitHub Desktop.
Get user access token for facebook test user using app access token.
val appId = "someId"
val appAccessToken = "someAppAccessToken"
def getTestUserAccessToken: Future[String] = {
val accessTokenEncoded = URLEncoder.encode(appAccessToken, "US-ASCII")
WS.url(s"https://graph.facebook.com/$appId/accounts/test-users?access_token=$accessTokenEncoded").get.map {
response =>
// for each returned user get the user id and access token
(response.json \ "data").as[JsArray].value.map {
case user: JsObject =>
val JsString(userId) = user \ "id"
val JsString(access_token) = user \ "access_token"
(userId, access_token)
// find the user
} find {
case (userId, _) => userId == testUserId
// return the access token
} map {
case (_, access_token) => access_token
// fail if it isn't found
} getOrElse {
fail("can't get user access token")
"asdf"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment