创建短推荐人链接
注:此功能在 SDK 12.1.1+ 版本中可用。一旦创建,短链接的有效期为 30 天。
使用短链接可将冗长、充满参数的奇异链接转换为更短、更安全的链接,方便共享。
通常情况下,您需要动态创建短链接,以便应用程序的用户可以与朋友分享,邀请他们使用应用程序。
要创建短链接,您需要
使用createReferrerShortLink方法创建短链接,如下图所示。
// Create a JSON object to add parameters to the Singular Link (if they don't exist in the link URL yet)
JSONObject params = new JSONObject();
try {
params.put("channel","sms");
params.put("another parameter","parameter value");
} catch (JSONException e) {
e.printStackTrace();
}
Singular.createReferrerShortLink (
"https://sample.sng.link/D52wc/cuvk?pcn=test", // The original Singular Link URL
"Referrer Name",
"Referrer ID",
params,
new ShortLinkHandler() {
@Override
public void onSuccess(final String shortLinkURL) {
view.post(new Runnable() {
@Override
public void run() {
// Add your share logic here
}
});
}
@Override
public void onError(final String error) {
view.post(new Runnable() {
@Override
public void run() {
// Logic to retry/abort/modify the params passed to
// the function, based on the cause of the error
}
});
}
});
// Create a JSON object to add parameters to the Singular Link (if they don't exist in the link URL yet)
val params = JSONObject()
try {
params.put("channel", "sms")
params.put("another parameter", "parameter value")
} catch (e: JSONException) {
e.printStackTrace()
}
Singular.createReferrerShortLink(
"https://sample.sng.link/D52wc/cuvk?pcn=test", // The original Singular Link URL
"Referrer Name",
"Referrer ID",
params,
object : ShortLinkHandler {
override fun onSuccess(shortLinkURL: String) {
view.post(Runnable {
// Add your share logic here
})
}
override fun onError(error: String) {
view.post(Runnable {
// Logic to retry/abort/modify the params passed to
// the function, based on the cause of the error
})
}
})