Created
June 1, 2012 20:16
-
-
Save flockonus/2854885 to your computer and use it in GitHub Desktop.
serveFacebookAppTab.java
This file contains hidden or 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
# Application dependencies | |
require: | |
- play 1.2.4 | |
- play -> fbgraph 0.4 |
This file contains hidden or 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
public static void tabAddCallback(Map<Long,Long> tabs_added) { | |
Set<Long> mySet = tabs_added.keySet(); | |
if( mySet.size() != 1){ | |
renderText("Sorry, you have to select exactly 1 page. In case you selected more than one you must manually remove the tabs them at each page, on facebook. If you selected none, please, try again."); | |
return; | |
} | |
Long pageId = mySet.iterator().next(); | |
// only go though with it, in case the user has secret and is loggedin | |
if( pageId != null ){ | |
//TODO persist the with the page_id | |
session.current().put("pageId", String.valueOf(pageId) ); | |
renderText("All working accordly, should add page_id to my user's business"); | |
} else { | |
renderText("Denied, something made no sense"); | |
} | |
} | |
/* | |
* POST | |
* Takes param from Facebook | |
{ | |
"algorithm":"HMAC-SHA256", | |
"expires":1338487200, | |
"issued_at":1338482438, | |
"oauth_token":"AAACNFcQjZCpQBACcNz6U2Xh5CENCfTtJJVxwMEuZBOvR1oeGbTzZBMPIi0kRndNlIobFqNjdlFUVX60HpGvjlIiYyQ752Kj80gi6UCNgQZDZD", | |
"page":{ | |
"id":"378035128900280", | |
"liked":true, | |
"admin":true}, | |
"user":{ | |
"country":"ca", | |
"locale":"en_US", | |
"age":{"min":21} | |
}, | |
"user_id":"683803412" | |
} | |
*/ | |
public static void tab(String signed_request) { | |
if( signed_request == null || signed_request.length() < 10){ | |
renderText("no request data"); | |
return ; | |
} | |
SignedRequest sr = new SignedRequest(signed_request);//sigSample); | |
if( sr.verify( Play.configuration.getProperty("fbg.appSecret") ) ){ | |
p("Verified request!"); | |
} else { | |
renderText("Failed to verify request"); | |
return ; | |
} | |
JsonObject reqData = sr.getData(); | |
// shows as JSON:renderText( reqData.getAsJsonObject() ); | |
JsonObject pageData = reqData.get("page").getAsJsonObject(); | |
renderText( pageData.get("id").getAsString() ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment