如何制作动态页面标签URL?

时间:2013-01-02 16:23:10

标签: php facebook facebook-graph-api

enter image description here

Facebook允许使用通配符域名。因此任何* .domain.com都可以在单个应用程序ID中使用。

现在,我想让每个粉丝专页都对我的应用提供唯一的Page Tab URL以及网址one.domain.comtwo.domain.com等示例。

子域名实际指向主应用程序&脚本将获得子域作为唯一ID。

https://developers.facebook.com/docs/appsonfacebook/pagetabs/

我发现signed_request可以添加其他参数&我有点迷失这个。

我是否知道如何确保每个粉丝专页都有唯一的网址?

2 个答案:

答案 0 :(得分:4)

  

我是否知道如何确保每个粉丝页面都有唯一的网址?

您只能设置一个页面标签网址(实际上是两个,一个用于HTTP,另一个用于HTTPS)。

您不能让不同的网页使用相同的应用作为网页标签,让他们从一开始就访问不同的网址。

您可以做的是检查您在signed_request参数中获得的页面ID - 然后,根据页面,重定向到您喜欢的位置或输出您喜欢的任何内容。

答案 1 :(得分:0)

<%@ 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

`