Make sure your phone has Internet connection.
I had followed the same code mentioned here. But Whenever I try to connect, I am getting this error always. Logs didn't help. What could be the issue?

` class MainActivity : AppCompatActivity() { lateinit var connectButton: ConnectButton
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
connectButton = findViewById(R.id.connect_button)
val provider: CredentialsProvider = object : CredentialsProvider {
override fun getOAuthCode(): String {
return "user_oauth_code"
}
override fun getUserToken(): String {
return "ifttt_user_token"
}
}
val uriResult = Uri.parse("smitchsecurity://connect_callback")
val configuration = ConnectButton.Configuration.newBuilder(
"[email protected]",
uriResult
)
.withConnectionId("MvTEYeDG")
.withCredentialProvider(provider)
.build()
connectButton.setup(configuration)
connectButton.addButtonStateChangeListener(object : ButtonStateChangeListener {
override fun onStateChanged(
currentState: ConnectButtonState,
previousState: ConnectButtonState,
connection: Connection
) {
Log.e("currentState ", "currentState $currentState")
Log.e("previousState ", "previousState $previousState")
Log.e("connection ", "connection $connection")
}
override fun onError(errorResponse: ErrorResponse) {
Log.e("The error Response ", "Error Response $errorResponse")
}
})
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
Log.e("onNewIntent", " ${intent}")
val connectResult = ConnectResult.fromIntent(intent)
connectButton.setConnectResult(connectResult)
}
}
`
and here is the manifest file
`
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.IFTTTPrimary">
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="smitchsecurity://connect_callback"
android:scheme="smitchsecurity://connect_callback" />
</intent-filter>
</activity>
</application>
`
The connection id doesn't seem to be valid, where did you get that?
Also, please make sure the redirect URL is correctly configured in your service on IFTTT Platform.
help me. I also got the same error I don't know how to generate REDIRECT_URI
@lzanita09 How are you so certain that the connection id doesn't seem to be valid?
const val CONNECTION_ID_GOOGLE_CALENDAR = "fWj4fxYg"
const val CONNECTION_ID_LOCATION = "pWisyzm7"
The same error occurs for both the above mentioned connection Ids in the sample app.
help me. I also got the same error I don't know how to generate REDIRECT_URI
@Bac-Pham the redirect URL is defined on our platform, please take a look at this document for details.
@RethinavelPillai the connection ID that you have in your code snippet, MvTEYeDG is not valid as the record isn't in our database.
Also, ifttt_user_token is also invalid as the user token, which is causing the SDK to fail fetching Connection data. If you don't have the user token just yet, you can return null.
@lzanita09 It would be helpful if the sdk could expose these errors to the client code so we can attempt to handle them gracefully and debug more easily during development. I wanted to cache the user token so I don't have to request a new one every time I show the button, but if the token is revoked, I have no way to detect it and the button just fails to load and gives the user this (not very helpful) error message. (I'll admit, I've fallen back on the generic "Network Error" message countless times myself, but it's really not proper error handling)