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 vscode的问题提问
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM