摘要:Android - 取得Facebook Page Id ,並用page Id 開啟Facebook App 粉絲頁
一般來講,我們常用的是Facebook Page Url
但如果要用Android 開啟 Android Facebook ,使用intent,需要使用的是fb:/profile/<page_id>
我們只有 https://www.facebook.com/<user_name>
這時,就需要使用
https://graph.facebook.com//<user_name>
取得id
再用id
使用fb://profile/<id>,打開FB App 導入相對的粉絲頁。
所以,我就做了一個,可以取得facebook page id的程式。
  
    public static String getFacebookPageId(Context ctx,String url) {
        String graphicId = "";
        
        try {
            String identifier = url.substring(url.lastIndexOf("/"));
            String graphUrl = "https://graph.facebook.com/" + identifier;
            JSONObject urlJsonData = getJson(ctx, graphUrl);
            if(urlJsonData.has("id")) {
                graphicId = urlJsonData.getString("id");
            }
        }catch(Exception ex) {
            ex.printStackTrace();
        }     
        
        return graphicId;
    }
    
    /**
     *  get Json Data Object
     */
    public static JSONObject getJson(Context ctx, String url) {
        AQuery aQuery = new AQuery(ctx);
        AjaxCallback cb = new AjaxCallback();
        cb.url(url).type(JSONObject.class);
        aQuery.sync(cb);
        JSONObject json = cb.getResult();
        return json;
    }  
得到id後再使用
    public static void openFbPage(Activity activity, String url)throws Exception {
        final String facebookAppPackageName = "com.facebook.katana";
        activity.getPackageManager().getPackageInfo(facebookAppPackageName, 0);
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        intent.setPackage(facebookAppPackageName);
        activity.startActivity(intent);
    }
使用,就可以開啟fb相對的粉絲頁內容
openFbPage(this,"fb://profile/<page_id>");