2013-04-05 98 views
0

在我使用VS2012 template構建的Facebook應用程序中,我不想擁有Facebook權限請求。如何查看粉絲是否喜歡我的Facebook頁面而不會觸發「likes」權限

該應用程序旨在充當facebook頁面的粉絲大門。所以我改編了下面的代碼和我的應用特定設置。此代碼是從 How to check if a user likes my Facebook Page or URL using Facebook's API。但現在應用程序彈出一個Facebook權限檢查,以允許訪問喜歡。

是否有另一種技術來檢查在我使用的環境中工作的喜歡?

<html> 
    <head> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
    <style type="text/css"> 
     div#container_notlike, div#container_like { 
     display: none; 
     } 
    </style> 
    </head> 
    <body> 
    <div id="fb-root"></div> 
    <script> 
     window.fbAsyncInit = function() { 
      FB.init({ 
       appId: 'YOUR_APP_ID', // App ID 
       channelUrl: 'http(s)://YOUR_APP_DOMAIN/channel.html', // Channel File 
       status: true, // check login status 
       cookie: true, // enable cookies to allow the server to access the session 
       xfbml: true // parse XFBML 
      }); 

      FB.getLoginStatus(function (response) { 
       var page_id = "YOUR_PAGE_ID"; 
       if (response && response.authResponse) { 
        var user_id = response.authResponse.userID; 
        var fql_query = "SELECT uid FROM page_fan WHERE page_id = " + page_id + "and uid=" + user_id; 
        FB.Data.query(fql_query).wait(function (rows) { 
         if (rows.length == 1 && rows[0].uid == user_id) { 
          console.log("LIKE"); 
          $('#container_like').show(); 
         } else { 
          console.log("NO LIKEY"); 
          $('#container_notlike').show(); 
         } 
        }); 
       } else { 
        FB.login(function (response) { 
         if (response && response.authResponse) { 
          var user_id = response.authResponse.userID; 
          var fql_query = "SELECT uid FROM page_fan WHERE page_id = " + page_id + "and uid=" + user_id; 
          FB.Data.query(fql_query).wait(function (rows) { 
           if (rows.length == 1 && rows[0].uid == user_id) { 
            console.log("LIKE"); 
            $('#container_like').show(); 
           } else { 
            console.log("NO LIKEY"); 
            $('#container_notlike').show(); 
           } 
          }); 
         } else { 
          console.log("NO LIKEY"); 
          $('#container_notlike').show(); 
         } 
        }, { scope: 'user_likes' }); 
       } 
      }); 
     }; 

     // Load the SDK Asynchronously 
     (function (d) { 
      var js, id = 'facebook-jssdk'; if (d.getElementById(id)) { return; } 
      js = d.createElement('script'); js.id = id; js.async = true; 
      js.src = "//connect.facebook.net/en_US/all.js"; 
      d.getElementsByTagName('head')[0].appendChild(js); 
     }(document)); 
    </script> 

    <div id="container_notlike"> 
     YOU DON'T LIKE ME :(
    </div> 

    <div id="container_like"> 
     YOU LIKE ME :) 
    </div> 

    </body> 
</html> 
+2

不要求許可,這是唯一可能的檢查用戶喜歡從頁面標籤應用(關鍵字:'signed_request')中訪問Facebook粉絲頁面。從_anywhere else_ resp通過API,不可能首先要求'user_likes'權限。 – CBroe 2013-04-05 09:46:03

回答

4

AS CBroe說,只有這樣,才能知道,如果用戶喜歡你的網頁,不求回報地喜歡許可,它的使用上頁面選項卡簽名的請求。

如果您的應用是頁面標籤,則在索引文件上會發布已簽名的請求。

的signed_request過帳爲JSON對象,這是一般的簽名的請求:

{ 
    "oauth_token": "...big long string...", 
    "algorithm": "HMAC-SHA256", 
    "expires": 1291840400, 
    "issued_at": 1291836800, 
    "registration": { 
     "name": "Paul Tarjan", 
     "email": "[email protected]", 
     "location": { 
     "name": "San Francisco, California", 
     "id": 114952118516947 
     }, 
     "gender": "male", 
     "birthday": "12/16/1985", 
     "like": true, 
     "phone": "555-123-4567", 
     "anniversary": "2/14/1998", 
     "captain": "K", 
     "force": "jedi", 
     "live": { 
     "name": "Denver, Colorado", 
     "id": 115590505119035 
     } 
    }, 
    "registration_metadata": { 
     "fields": "[\n {'name':'name'},\n {'name':'email'},\n {'name':'location'},\n {'name':'gender'},\n {'name':'birthday'},\n {'name':'password'},\n {'name':'like',  'description':'Do you like this plugin?', 'type':'checkbox', 'default':'checked'},\n {'name':'phone',  'description':'Phone Number',    'type':'text'},\n {'name':'anniversary','description':'Anniversary',    'type':'date'},\n {'name':'captain', 'description':'Best Captain',    'type':'select', 'options':{'P':'Jean-Luc Picard','K':'James T. Kirk'}},\n {'name':'force',  'description':'Which side?',    'type':'select', 'options':{'jedi':'Jedi','sith':'Sith'}, 'default':'sith'},\n {'name':'live',  'description':'Best Place to Live',  'type':'typeahead', 'categories':['city','country','state_province']},\n {'name':'captcha'}\n]" 
    }, 
    "user_id": "218471" 
} 

如果您解析此JSON對象到一個數組,如果你的應用程序是一個頁面標籤 通過這樣做,signed_request['page']['liked']如果用戶喜歡你的頁面,你會得到TRUE或者如果他不喜歡,你可以得到

您可以在此處詳細瞭解解析標誌requeste: https://developers.facebook.com/docs/howtos/login/signed-request/

有關每個應用程序類型,在特定領域

多: https://developers.facebook.com/docs/reference/login/signed-request/

+0

感謝您的回答。我發現了更多關於你在我的ASP.Net [link](http://stackoverflow.com/questions/7891303/decode-signed-request-without-authentication)中建議的技術的信息。希望今天能夠測試它。 – tab 2013-04-08 04:10:54

相關問題