Implementing Callbacks
In your Activity/Fragment where you want to integrate the Truecaller OAuth flow, either make the component implement the interface TcOAuthCallback or create an instance of it which you would require to initialize TcSdkOptions in the next step.
The interface has 2 functions which need to be overridden -
private val tcOAuthCallback: TcOAuthCallback = object : TcOAuthCallback {
override fun onSuccess(tcOAuthData: TcOAuthData) {
..
}
override fun onFailure(tcOAuthError: TcOAuthError) {
..
}
}
onFailure() method will be called in case of an error. You would get the error details like the error code and error message through tcOAuthError returned with this method.
onSuccess() method will be called when the user gives consent to authorize your app by tapping on the primary button on the Truecaller’s consent screen, and subsequently, an authorization code will be successfully generated and received. This method would return tcOAuthData, which contains information like : Auth Parameters [Live]
authorizationCode - which you can utilize to fetch the user’s access token
scopesGranted - list of scopes granted by the user
state - state parameter returned by the authorisation server. If the state set by your application is the same as the state returned by the authorisation server, it’s safe to proceed further. If state parameters are different, someone else has initiated the request and it could be a case of request forgery.
Sim and Device Info Parameters[EAP - for access, mail us at [email protected]]
Sim Status - This will be a parameter returned to you in successCallback, which helps understand whether the number passed to you is actually present on the device at the time of verification. In case it is present, the variable returns 1, In case it's not present, the variable returns 0, and in case, due to OS level restrictions, the SDK is not able to detect it, the variable returns -1
Device Code - This parameter helps you tie the number onboarded on your platform to a particular device identifier. This parameter for a user on a device will always be the same until the Truecaller profile is changed on that very device OR the user is using some other device to verify their number.
Call onActivityResultObtained() within the registerForActivityResult() like below:
val launcher = registerForActivityResult(StartActivityForResult()) { result: ActivityResult ->
TcSdk.getInstance().onActivityResultObtained(requireActivity(), result.resultCode, result.data)
}
and then assign it to a variable (Ex: launcher) to use it under step 13 (Invocation).
Last updated