Last active
August 29, 2015 14:07
-
-
Save pj/3904d708ad1242386760 to your computer and use it in GitHub Desktop.
Get user access token for facebook test user using app access token.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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