Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure your phone has Internet connection. #216

Open
RethinavelPillai opened this issue Jan 6, 2021 · 6 comments
Open

Make sure your phone has Internet connection. #216

RethinavelPillai opened this issue Jan 6, 2021 · 6 comments

Comments

@RethinavelPillai
Copy link

RethinavelPillai commented Jan 6, 2021

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?

WhatsApp Image 2021-01-06 at 6 05 45 PM

`
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>
`
@lzanita09
Copy link
Collaborator

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.

@Bac-Pham
Copy link

help me.
I also got the same error I don't know how to generate REDIRECT_URI

@RethinavelPillai
Copy link
Author

RethinavelPillai commented Jan 27, 2021

@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.

@lzanita09
Copy link
Collaborator

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.

@lzanita09
Copy link
Collaborator

@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.

@acrimi
Copy link

acrimi commented May 20, 2021

@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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants