如何实现Facebook共享,然后在Android App中使用深层链接(打开我的应用程序)发布发布的深层链接?

时间:2018-12-03 11:25:59

标签: android facebook-android-sdk facebook-share

我想为Facebook应用发布实现深层链接。 首先,我想在Facebook Post上分享我的App内容,然后当用户点击该Post时,如果用户已经安装了该App,则打开app,否则将打开App链接。

我遵循https://developers.facebook.com/docs/applinks/androidhttps://developers.facebook.com/docs/sharing/android#linkshare,但没有用

如何在Facebook上使用LinkShare共享此数据

target_url:“ https://developers.facebook.com/android” 附加功能:   fb_app_id:[YOUR_FACEBOOK_APP_ID]   fb_access_token:“ [ACCESS_TOKEN]”   fb_expires_in:3600

1 个答案:

答案 0 :(得分:1)

要实现深度链接和共享在一起,需要使用branch.io

来实现此功能

添加依赖项:

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

将此代码添加到Launcher活动内的清单文件中

  <!-- 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>    

将此代码添加到启动器活动中,您将通过此方法获取链接和数据

@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