One of the most interesting aspects of sharing to Facebook from your app is that when people engage with the feed stories posted from your app, those stories can send people to your app or your app's Google Play listing, driving traffic and app installs. You can implement this behavior using App Links.
Facebook's Mobile Hosting API for App Links:
If your application doesn't have a website for content you want to share to Facebook, you don't have public web URLs which you can annotate to support App Links.
For these types of apps, Facebook provides an App Links Hosting API that will host App Links for you. With the Hosting API you can create and manage your App Links for all the mobile environments you support.
This is the typical flow to configure an App Link for a piece of content:
Please follow below steps for generate app linking.
For web service, In request Params we need to send below parameters.
You create a new App Link object for a content targeted to iOS & Android like this
A successful call returns an ID that represents the App Link object hosted on Facebook,
for example:
Return : {"id":"643402985734254"}
You can retrieve the canonical URL that points to your new App Link object through this API call:
Where
The filter should respond to the
For example, if I see a story on my Facebook feed about one of my friends completing this share tutorial and I tap on it, I will expect to be redirected to a view in your app that features this tutorial and not to your app's main activity.
If you use the App Links Hosting API, the
In the code sample below, we're simply logging the target URL, but you should direct people through the appropriated flow for your app:
App link Flow
Facebook's Mobile Hosting API for App Links:
If your application doesn't have a website for content you want to share to Facebook, you don't have public web URLs which you can annotate to support App Links.
For these types of apps, Facebook provides an App Links Hosting API that will host App Links for you. With the Hosting API you can create and manage your App Links for all the mobile environments you support.
This is the typical flow to configure an App Link for a piece of content:
- Create a new App Link object. You can set up an object for one platform or several at the same time.
- Save the App Link object ID that's returned.
- Use that ID to get the URL you can use to share the content.
- Configure additional platforms that you support.
- If supporting Android, configure your app's manifest file for the configured URLs.
Please follow below steps for generate app linking.
For web service, In request Params we need to send below parameters.
iOS: url, name
Android: url, name
Step #1: Generate App Access Token (Ref. https://developers.facebook.com/docs/facebook-login/access-tokens#apptokens)
GET /oauth/access_token? client_id={app-id} &client_secret={app-secret} &grant_type=client_credentials
Step #2: Generate App Link using generated App Access Token (Ref.https://developers.facebook.com/docs/applinks/hosting-api)
You create a new App Link object for a content targeted to iOS & Android like this
curl https://graph.facebook.com/app/app_link_hosts \-F access_token="APP_ACCESS_TOKEN" \
-F name="iOS App Link Object Example" \
-F ios=' [
{
"url" : "applinkFB://showApp/54eee6292658c7df25000004",
"app_store_id" : 570281083,
"app_name" : “appName”,
},
]' \
-F android=' [
{
"url" : "applinkFB://showApp/54eee6292658c7df25000004",
"package" : "com.packagename”,
"app_name" : “appName”,
},
]' \
-F web=' {
"should_fallback" : false,
}'
A successful call returns an ID that represents the App Link object hosted on Facebook,
for example:
Return : {"id":"643402985734254"}
Step #3: Using generated ID(YOUR_APP_LINK_HOST_ID) which represents the App Link, you need to call another API which will return "canonical_url"
You can retrieve the canonical URL that points to your new App Link object through this API call:
curl -G https://graph.facebook.com/YOUR_APP_LINK_HOST_ID \
-d access_token="APP_ACCESS_TOKEN" \
-d fields=canonical_url \
-d pretty=true
Where
YOUR_APP_LINK_HOST_ID
represents the id returned from creating your App Link object. Your response will look like this:
Return:
{ "canonical_url": "https://fb.me/643402985734254", "id": "643402985734254"
}
Support sharesample URLs in Android
When a shared link is tapped your Android app is launched through the URL specified in the App Link object you just created (if you didn't specify a url, then it will use the canonical URL - i.e. the https://fb.me/xxxxx URL). To set up your app to respond to this URL, you need to add an intent filter in your app's manifest file.The filter should respond to the
applinkFB
scheme (if you didn't specify a URL, then your filter should respond to the fb.me host and https scheme), handle implicit intents, and accept the ACTION_VIEW
action. The example below adds an intent filter to the MainActivity that handles this:
Once you've set up your web pages based App Links,
you're ready to handle incoming links to your app.
Handling incoming links
To ensure an engaging user experience, you should process the incoming intent information when your app is activated and direct the person to the object featured in the story they're coming from.For example, if I see a story on my Facebook feed about one of my friends completing this share tutorial and I tap on it, I will expect to be redirected to a view in your app that features this tutorial and not to your app's main activity.
If you use the App Links Hosting API, the
Intent
data will look like this:data: "
applinkFB://showApp/54eee6292658c7df25000004?target_url=https%3A%2F%2Ffb.me%2F643402985734299"
extras:
al_applink_data: <Bundle containing App Link data>
In the code sample below, we're simply logging the target URL, but you should direct people through the appropriated flow for your app:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(this);
...
Uri targetUrl =
AppLinks.getTargetUrlFromInboundIntent(this, getIntent());
if (targetUrl != null) {
Log.i("Activity", "App Link Target URL: " + targetUrl.toString());
}
}
References:
You can get more details about overall implementation at
Goodd post
ReplyDelete