2016-07-13 34 views
0

我有以下的Facebook代碼鏈接在本地Facebook應用程序中打開。它工作正常,但僅適用於此處給出的配置文件ID url = "fb://profile/100012746891816";。 如果有人可以幫助和編輯我的代碼,並使其在Facebook上的幾個配置文件或網頁上工作,並自動生成Facebook的身份證。如何使網站上的幾個Facebook鏈接在Facebook本機應用程序中打開並自動生成Facebook配置文件或頁面數字ID

這裏是如何通過連接php <a href="<?php echo "http://facebook.com/".$fbk; ?>">$fbk包含Facebook頁面或配置文件名稱。

if (url.contains("http://facebook.com")) { 
    Uri uri = Uri.parse(url); 
    try { 
     url = "fb://profile/100012746891816"; 
     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); 
     startActivity(intent); 
    } catch(Exception e) { 
     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); 
    } 
    return true; 
} 
+0

在這方面的幫助? –

回答

0

你可以嘗試這樣的事情:

private static final String FB_BASE = "facebook.com/"; 

public void openFacebookProfile(String profileUrl){ 
    try{ 
     Uri uri = null; 

     int versionCode = getPackageManager() 
       .getPackageInfo("com.facebook.katana", 0) 
       .versionCode; 

     if(versionCode >= 3002850) 
      uri = Uri.parse("fb://facewebmodal/f?href=" + profileUrl); 
     else { 
      String profileId = profileUrl.substring(profileUrl.indexOf(FB_BASE) + FB_BASE.length()); 

      uri = Uri.parse("fb://profile/" + profileId); 
     } 

     startActivity(new Intent(Intent.ACTION_VIEW, uri)); 
    } 
    catch(Throwable e){ 
     startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(profileUrl))); 
    } 
} 

只要網址中包含「facebook.com/」,它應該剝去結束輪廓ID(假設沒有尾隨數據) ,然後通過正確的本地FB平臺打開,或者默認打開網頁。

+0

如果是頁面然後???你是否可以編輯和包含頁面也是 –

+0

FB配置文件和頁面URL有相同的結構,所以沒有辦法區分2,除非你明確地告訴它它是哪種類型,這有點超出了原始問題的範圍,但是我所提供的不僅僅是指向正確的方向(提示:請看else語句) – Guardanis

相關問題