Facebook allowed wildcard domain. So any *.domain.com can be use within single application ID.
Now I want to make every Fan Page will have unique Page Tab URL
to my app and the example of URLs one.domain.com
, two.domain.com
and more.
The subdomain actually point to main app & script will get the subdomain as unique id.
https://developers.facebook.com/docs/appsonfacebook/pagetabs/
I found signed_request
can add additional parameter & I'm a bit lost about this one.
May I know the logic how to make sure every Fan Page will have unique URL?
May I know the logic how to make sure every Fan Page will have unique URL?
You can only set one Page Tab URL (well two actually, one for HTTP and one for HTTPS).
You can not have different pages use the same app as a page tab and have them access different URLs from the start.
What you can do, is check the page id that you get inside the signed_request parameter – and after that, depending on the page, redirect to wherever you like or output whatever you like.
<%@ page import ="java.io.*,java.util.*" %> <%@ page import = "java.util.Arrays,javax.crypto.Mac,javax.crypto.SecretKey,javax.crypto.spec.SecretKeySpec" %> <%@ page import = "org.json.simple.parser.*,org.apache.commons.codec.binary.Base64" %> <%@ page import = "java.io.UnsupportedEncodingException,javax.xml.bind.DatatypeConverter" %> <%
if (request.getParameter("signed_request") != null) {
String input = request.getParameter("signed_request");
//input ="q3v8X8hbmkKXaF_DZaLBPapMPVjMgpq8bZe-SmYc6Fs.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImlzc3VlZF9hdCI6MTUxMjYyOTY5MiwicGFnZSI6eyJpZCI6IjEzOTg4MTM1MDM3NTUyMzEiLCJhZG1pbiI6dHJ1ZSwibGlrZWQiOnRydWV9LCJ1c2VyIjp7ImNvdW50cnkiOiJpbiIsImxvY2FsZSI6ImVuX0dCIiwiYWdlIjp7Im1pbiI6MjF9fX0";
String secretKey = "d8e6e697b9c958a8ee8f2e";
int max_age = 3600;
try
{
String[] split = input.split("[.]", 2);
String encoded_sig = split[0];
String encoded_envelope = split[1];
JSONParser parser = new JSONParser();
// check
//out.println("<br>"+ new String(new Base64(true).decode(encoded_envelope)));
Map envelope = (Map) parser.parse(new String(new Base64(true).decode(encoded_envelope)));
String algorithm = (String) envelope.get("algorithm");
if (!algorithm.equals("HMAC-SHA256")) {
throw new Exception("Invalid request. (Unsupported algorithm.)");
}
if (((Long) envelope.get("issued_at")) < System.currentTimeMillis() / 1000 - max_age) {
throw new Exception("Invalid request. (Too old.)");
}
byte[] key = secretKey.getBytes();
SecretKey hmacKey = new SecretKeySpec(key, "HMACSHA256");
Mac mac = Mac.getInstance("HMACSHA256");
mac.init(hmacKey);
byte[] digest = mac.doFinal(encoded_envelope.getBytes());
if (!Arrays.equals( new Base64(true).decode(encoded_sig), digest)) {
throw new Exception("Invalid request. (Invalid signature.)");
}
String pageId = ((Map)envelope.get("page")).get("id").toString();
if(pageId.equals("1398813503755231")){
response.sendRedirect("https://yourdomain.com/1111");
}
else if(pageId.equals("151433128812548")){
response.sendRedirect("https://yourdomain1.com/2222");
} }
catch(Exception e)
{
out.println("error"+e);
} } %> <html> <head> Facebook Store <script> var appId = 'your app id'; var pageId=''; window.fbAsyncInit = function() {
FB.init({
appId : appId,
autoLogAppEvents : true,
xfbml : true,
version : 'v2.11'
}); }; (function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); function createPageTab(){
FB.ui(
{
method: 'pagetab',
redirect_uri:'https://9d5b71a7.ngrok.io/facebook-store.jsp'
},
function(response) {
console.log(JSON.stringify(response));
if (response != null && response.tabs_added != null) {
for( pageid in response.tabs_added){
pageId = pageid;
}
}
}
); }
function viewPageTab(){
var url = 'https://facebook.com/pages/-/'+pageId+'?sk=app_'+appId;
window.open(url,'_blank'); }
</script> </head> <body>
<button onClick="createPageTab()" >Connect your store with facebook </button>
<button onClick="viewPageTab();" > View your Store </button> </body> </html
>
1. `
> Blockquote
`