note: Facebook App 判斷有無加入粉絲團

2014050822:01

之前的寫法一直 OK

        FB.api('/me/likes/粉絲團編號', function (response) {

            if (response.data.length == 0) {
            
                console.log('還沒加入粉絲團已經加入了');

            } else {

                 console.log('已經加入了');

            }
        });

或是

        FB.api('/me/likes/粉絲團編號', function (response) {

        console.log(response.data.length );

            if (response.data.length == 0) {

                console.log('還沒加入粉絲團已經加入了');

            } else {

                 console.log('已經加入了');

            }
        });


但這兩天新開的 FB App 都無法正常回傳正確資料
(明明已經加了粉絲頁  ??!!)

但,改套用很久以前開設的 appId 卻都可正常回應 有否加入粉絲頁 ///


現,改用 FQL 來查詢 都 OK 了


FB.api({
    method: "fql.query",
    query: "SELECT uid FROM page_fan WHERE uid = '" + fb_uid + "' AND page_id = '粉絲團編號'"
},  function(response) {

        if(response){

                 console.log('已經加入了');

        } else {

                console.log('還沒加入粉絲團已經加入了');

        }
    }
);


ref

Review Guidelines (Facebook)

Upgrading from Version 1.0 to Version 2.0 (Facebook Platform Upgrade Guide)


pages.isFan returns incorrect signature

Facebook API: Check If A User Is Fan Of A Facebook Page


*** 更新

新的 FB App 政策
若需要額外存取用戶訊息(如 user_likes、user_photos)需說明 App 的內容、截圖 供 FB 官方人工審核


Permissions with Facebook Login
https://developers.facebook.com/docs/facebook-login/permissions/v2.0


***
關於 FB UID (user-id)

過去 要查到 UID 還蠻容易的
不管是用 API 或是直接於 FB 頁面上 都可輕易取得
現在政策有改

現在 新申請的 FB AppId
透過 FB 相關 API 所取得用戶 UID 已經有保護、無法取得真正的用戶 UID
每個 App 取得的 UID 都不一樣 (之前申請的 App 不受影響)

原本 要查詢 FB Graph 用戶資料,
只要
https://graph.facebook.com/[真實 FB UID]

https://graph.facebook.com/[個人網址username , 如 michael ]

就會出現幾項基本資料:
例如
https://graph.facebook.com/zuck
or
https://graph.facebook.com/4

{
   "id": "4",
   "first_name": "Mark",
   "gender": "male",
   "last_name": "Zuckerberg",
   "link": "https://www.facebook.com/zuck",
   "locale": "en_US",
   "name": "Mark Zuckerberg",
   "username": "zuck"
}

現在要加上 access token 才能查到用戶資料,例如:
https://graph.facebook.com/[FB 給的假 UID]?access_token=xxxxxxx
有帶入正確的 access_token 則回覆:
{
   "id": "730423090311111",
   "email": "aabbccdd\u0040yahoo.com.tw",
   "first_name": "Moo",
   "gender": "male",
   "last_name": "Lee",
   "link": "https://www.facebook.com/app_scoped_user_id/730423090311111/",
   "locale": "zh_TW",
   "name": "Moo Lee",
   "timezone": 8,
   "updated_time": "2014-01-15T13:16:45+0000",
   "verified": true
}



沒帶入 access_token 則:
{
   "error": {
      "message": "(#803) Some of the aliases you requested do not exist: profile.php",
      "type": "OAuthException",
      "code": 803
   }
}

或是帶入已過期的 access_token:
{
   "error": {
      "message": "Error validating access token: Session has expired on 2014\u5e746\u67089\u65e5 18:00. The current time is 2014\u5e746\u67089\u65e5 23:08.",
      "type": "OAuthException",
      "code": 190,
      "error_subcode": 463
   }
}



但若要查詢用戶動態時報,則可以
https://www.facebook.com/app_scoped_user_id/[FB 給的假 UID]
此網址會自動轉到 redir 用戶個人的 FB 動態時報

例如
https://www.facebook.com/app_scoped_user_id/7333865611111
會轉到類似這樣網址:
https://www.facebook.com/profile.php?id=10000123123123   (ps: 虛構的網址)



FB 大頭貼網址
不變
https://graph.facebook.com/[FB 給的假(或真) UID]/picture
會自動再轉到另一個圖片網址

(以前相片網址中 就帶有 UID,現在沒了..)

***

Graph API Explorer
https://developers.facebook.com/tools/explorer/?method=GET&path=me&version=v2.0

 


  •    (悄悄話) 1F
  • <悄悄話留言,不公開>