douliu3831 2011-09-10 15:32
浏览 19
已采纳

为管理员创建Facebook应用程序选项卡

I need to pass in user information (ie: userID, email address) from my portal into a Facebook app so that their profile shows on their Facebook tab when they grant access to use the application.

So far, I decided to create an admin landing page/dashboard on Facebook, so that they can enter their email and password. I can then retrieve their userID to add to the Facebook tab, and it will load all of their information.

Right now, I need Facebook to know that I am passing in that value, and load it to the users Facebook Like page.

I am not sure if this is the proper method to use, or where I should begin.

  • 写回答

1条回答 默认 最新

  • dongzhong7299 2011-09-10 17:35
    关注

    If I understand your question correctly you want to know a general pattern for admin pages in Facebook apps.

    What I usually do is identify whether or not the person viewing your page is an admin, and if so output a secure link to your editing page, which would then connect via Facebook and verify the user again before showing whatever forms you need to perform the administration tasks.

    To determine if a user is an admin of the page: When you parse the signed request data, you should see a page.admin value. If you don't get any signed request data you can safely assume the user isn't an admin. You can use the PHP SDK to parse the signed request data or write your own stuff. I wrote my own library because I found the PHP SDK a bit hard to use. https://bitbucket.org/tlack/xfb

    Once you know if they are an admin, output a link to your admin page. On that page do the typical FB Connect stuff with the JS SDK. Here's a little example I use in my Domain Trip Facebook app to request and store an offline access token that I use to manipulate the page later:

      <div id="fb-root"></div>
      <script src="http://connect.facebook.net/en_US/all.js"></script>
      <script type="text/javascript">
      FB.init({
        appId  : '<?= $app_id; ?>',
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        oauth  : true // enable OAuth 2.0
      });
      function login() {
        var callback = function(response) {
          if (response.authResponse) {
            console.log('Welcome!  Fetching your information.... ');
            FB.api('/<?= $_REQUEST['id']; ?>?fields=access_token',
              function(response) {
                if (response.access_token) {
                  document.location = 'edit_permission.php?id=<?= $_REQUEST['id']; ?>&at='+response.access_token;
                } else {
                  alert("Could not get permission to access page. Please contact help@domaintrip.com");
                }
              }
            );
          } else {
            document.location = '<?= get_my_url(); ?>&f=1';
          }
        };
        FB.login(callback, {scope: 'offline_access,manage_pages'});
      }
      </script>
      <p>
        We need permission to interact with your Facebook page.
      </p>
      <p>
        <button onclick="login(); return false;">Login Now</a>
      </p>
    

    If you want to get really fancy, you could have the admin editing UI in the main page itself, unfolding when a button is clicked.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态