# Implementing Callbacks

4. 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.<br>

  **\[New] Sim Info Parameters**\[EAP - for access, mail us at <developersupport@truecaller.com>]

  * 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<br>

5. 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 <sub>(Ex: launcher)</sub>  to use it under step 13 ([Invocation](https://docs.truecaller.com/truecaller-sdk/~/revisions/nSPuRXISTt65PkMyKKJS/android/oauth-sdk-3.2.0/integration-steps/invocation)).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.truecaller.com/truecaller-sdk/android/oauth-sdk-3.2.0/integration-steps/implementing-callbacks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
