web-dev-qa-db-ja.com

指定されたプロファイルページでFacebookアプリを開く

SOのコードを使用しようとしていますが、失敗します:

これらは、アプリの右側のセクションを開くことになっているURIです。

facebook://facebook.com/info?user=544410940     (id of the user. "patrick.boos" won't work)
facebook://facebook.com/wall?user=544410940   (will only show the info if you have added it as 

私が欲しいのは、私が指定したプロファイルでFacebookアプリを開くことです。これは私が試しているコードです。番号はプロファイルのUIDです。

        String uri = "facebook://facebook.com/wall?user=417079614970109"; 
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        startActivity(intent);

減価償却されているのですか、それとも何ですか?どうすればそのようなタスクを今実行できますか?

17
Jacek Kwiecień

実はこんな感じです。これらのURIは、Facebookアプリの最新バージョンでのみ機能します。だから私たちはキャッチを試みます。

public static Intent getOpenFacebookIntent(Context context) {

    try {
        context.getPackageManager()
                .getPackageInfo("com.facebook.katana", 0); //Checks if FB is even installed.
        return new Intent(Intent.ACTION_VIEW,
                Uri.parse("fb://profile/254175194653125")); //Trys to make intent with FB's URI
    } catch (Exception e) {
        return new Intent(Intent.ACTION_VIEW,
                Uri.parse("https://www.facebook.com/arkverse")); //catches and opens a url to the desired page
    }
}

アクティビティで開くには、次のように呼び出します。

Intent facebookIntent = getOpenFacebookIntent(this);
startActivity(facebookIntent);
52
Zaid Daghestani

これは簡単ではありませんか?たとえば、onClickListener内ですか?

    try{ 

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/426253597411506"));
        startActivity(intent);

       }catch(Exception e){

         startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.facebook.com/appetizerandroid")));

      }

PS。 http://graph.facebook.com/ [userName] からID(多数)を取得します

11
John

これはもう機能しません

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/someProfile"));

代わりにこれを試してください

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href=https://www.facebook.com/someProfile"));
10
Tristan Richard

今のところそれは不可能です、Facebookこの機能は削除されました

2

これについては非常に多くの質問がありますが、このコードは私のために機能します。Facebookはそこでポリシーを変更したので、詳細についてはこのFacebookの公式を確認してくださいGRAPH API Explorer PAGE

Intent intent = null;
    try {
        getPackageManager().getPackageInfo("com.facebook.katana", 0);
        String url = "https://www.facebook.com/"+idFacebook;
        intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://facewebmodal/f?href="+url));
    } catch (Exception e) {
        // no Facebook app, revert to browser
        String url = "https://facebook.com/"+idFacebook;
        intent = new Intent(Intent.ACTION_VIEW);
        intent .setData(Uri.parse(url));
    }
    this.startActivity(intent);
2
Shailesh

これを行うには、「FacebookページID」が必要です。取得できます。

  • ページから「About」に移動します。
  • 「詳細」セクションに移動します。

introducir la descripción de la imagen aquí

指定されたプロフィールページでFacebookアプリを開くには、

あなたはこれを行うことができます:

 String facebookId = "fb://page/<Facebook Page ID>";
  startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(facebookId)));
1
Jorgesys

Facebookページの場合は次のように使用します: http:// fb:// page/87268309621xxxx 個人IDの場合は次のように使用します: http:// fb:// profile/87268309621xxxx

1
abir99