簡體   English   中英

檢查用戶是否喜歡

[英]Check If a User liked

我有一個可以在Facebook之外運行的應用程序。 在瀏覽之前,我需要用戶喜歡2個不同的Facebook頁面。

我已經有了一個功能,可以知道用戶是否單擊了(當然喜歡)那些頁面。 問題是用戶是否已經喜歡這些頁面。 因此,如果用戶不喜歡。 當他單擊2個贊按鈕時,我會知道。

我將在數據庫中添加一個liked_both = 1,從那時起,我將始終使客戶端跳過該步驟。 這不是一個好習慣,因為如果用戶刪除like之類的內容,由於我在數據庫中進行了驗證,他將跳過該內容。

這是我使用的代碼:

  window.fbAsyncInit = function() {
        FB.init({
            appId: '1426818840916389',
            status: true,
            cookie: true,
            xfbml: true,
            oauth: true
        });

        FB.Event.subscribe('edge.create', function(response) {
           //Some ajax function.
        });

    });

我可以用它來了解用戶是否單擊。 但是,如何知道他們是否已經單擊而不要求權限。

另外,我沒有時間要求提交審核意見(真的有必要嗎?)。

我也試過這個:

FB.login(function(response) {

    if (response) {
            console.log(response);
          var user_id = '100000246250649';

          var page_id = "40796308305"; //coca cola
          var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+" and uid="+user_id;

          var the_query = FB.Data.query(fql_query);

          the_query.wait(function(rows) {

              if (rows.length == 1 && rows[0].uid == user_id) {
                   alert(' LIKE');
                  //here you could also do some ajax and get the content for a "liker" instead of simply showing a hidden div in the page.

              } else {
                 alert('DO NOT LIKE');//and here you could get the content for a non liker in ajax...
              }
          });


      } else {

        // user is not logged in
      }

我只得到“回應”:

對象{authResponse:對象,狀態:“已連接”}

即使我定義了UID和PAGE_ID,查詢也不會運行,我也不會收到任何錯誤,也沒有響應。

也許我沒有選擇,就我搜索而言,這幾乎是不可能的,但也許有些聰明的主意就能為我提供幫助。

您可以使用圖形API查詢用戶喜歡的所有頁面:

FB.api("/me/likes",function (response) {});

請注意,要執行此操作,您將需要獲得user_likes權限。

https://developers.facebook.com/docs/graph-api/reference/v2.0/user/likes https://developers.facebook.com/docs/facebook-login/permissions/v2.0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM