android - 如何在 Android 应用程序中使用深度链接(打开我的应用程序)实现 Facebook 共享然后深度链接该帖子?

标签 android facebook-android-sdk facebook-share

我想为 Facebook 应用帖子实现深度链接。 首先,我想在 Facebook Post 上分享我的 App 内容,当用户点击帖子时,如果用户已经安装了该应用程序,则打开应用程序,否则它将打开应用程序链接。

我关注 https://developers.facebook.com/docs/applinks/androidhttps://developers.facebook.com/docs/sharing/android#linkshare但它不起作用

如何在 facebook 上使用 LinkShare 分享这些数据

目标网址:“https://developers.facebook.com/android” Actor : fb_app_id: [YOUR_FACEBOOK_APP_ID] fb_access_token:“[ACCESS_TOKEN]” fb_expires_in: 3600

最佳答案

要同时实现深度链接和共享,需要使用 branch.io 实现此功能

添加依赖:

 compile 'com.google.android.gms:play-services-appindexing:9.+' 

将此代码添加到 Launcher Activity 内的 list 文件中

  <!-- Branch URI Scheme -->
        <intent-filter>
            <data android:scheme="androidexample" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>

        <!-- Branch App Links (optional) -->
        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https" android:host="example.app.link" />
            <data android:scheme="https" android:host="example-alternate.app.link" />
        </intent-filter>    

将此代码添加到您的 Launcher Activity,您将在此方法中获取您的链接和数据

@Override
public void onStart() {
    super.onStart();

    // Branch init
    Branch.getInstance().initSession(new Branch.BranchReferralInitListener() {
        @Override
        public void onInitFinished(JSONObject referringParams, BranchError error) {
            if (error == null) {
                Log.i("BRANCH SDK", referringParams.toString());
                // Retrieve deeplink keys from 'referringParams' and evaluate the values to determine where to route the user
                // Check '+clicked_branch_link' before deciding whether to use your Branch routing logic
            } else {
                Log.i("BRANCH SDK", error.getMessage());
            }
        }
    }, this.getIntent().getData(), this);
}    

在MyApplication类中添加这段代码

 // Branch logging for debugging
    Branch.enableLogging();

 // Branch object initialization
    Branch.getAutoInstance(this);   

您可以使用此代码创建深层链接

 LinkProperties lp = new LinkProperties()
.setChannel("facebook")
.setFeature("sharing")
.setCampaign("content 123 launch")
.setStage("new user")
.addControlParameter("$desktop_url", "http://example.com/home")
.addControlParameter("custom", "data")
.addControlParameter("custom_random", 
Long.toString(Calendar.getInstance().getTimeInMillis()));

buo.generateShortUrl(this, lp, new 
Branch.BranchLinkCreateListener() {
@Override
public void onLinkCreate(String url, BranchError error) {
    if (error == null) {
        Log.i("BRANCH SDK", "got my Branch link to share: " + url);
    }
}
});    

refer this for Android

refer this for ios

关于android - 如何在 Android 应用程序中使用深度链接(打开我的应用程序)实现 Facebook 共享然后深度链接该帖子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53592842/

相关文章:

Android Studio 代码样式方案每次启动时自动重置为默认值

java - android中如何解决异常

facebook - 使用新权限获取无效范围 pages_show_list

android - 如何解决 Facebook 工具 :replace ="android:theme"?

javascript - 当信息由 javascript 动态创建时,如何从网页上的表格中抓取信息?

android - 如何使用多个 TouchDelegate

android - Facebook SDK 错误 : Session provided to a request in un-opened state

ios - 通过 UIActivityViewController 的 Facebook 共享不会在共享对话框中显示所有事件项目

由于嵌入式浏览器,Android Facebook 分享对话框阻止登录

ios - 如何使我的 SLComposeViewController 可用于服务类型 (Facebook) iOS swift