vk-android-sdk icon indicating copy to clipboard operation
vk-android-sdk copied to clipboard

VK.execute(AccountService().accountGetProfileInfo(), object : VKApiCallback<AccountUserSettings> does not work

Open AZEY4 opened this issue 4 years ago • 3 comments

Hello, I try to get user first and second name using this request in onLogin method in VKAuthCallback. I do it like this:

vkCallback = object : VKAuthCallback {
            override fun onLogin(token: VKAccessToken) {
                VK.execute(AccountService().accountGetProfileInfo(), object : VKApiCallback<AccountUserSettings> {
                    override fun success(result: AccountUserSettings) {
                        onVkSignIn(token, result.firstName + " " + result.lastName)
                        Toast.makeText(contextEx, "API OK", Toast.LENGTH_LONG).show()
                    }

                    override fun fail(error: Exception) {
                        Toast.makeText(contextEx, "Error", Toast.LENGTH_LONG).show()
                    }
                })
                Toast.makeText(contextEx, "Login success", Toast.LENGTH_LONG).show()
            }

            override fun onLoginFailed(errorCode: Int) {
                onSignInFailed()
                Toast.makeText(contextEx, "Error", Toast.LENGTH_LONG).show()            }
        }

So, the toast "Login success" is shown but onVkSignIn is not called. And I have no exceptions or something else strange in logs or somewhere else. I guess it is just not started. Can somebody help me? What can be wrong?

AZEY4 avatar Aug 21 '21 19:08 AZEY4

Hello. I've just tried to do the same and got AccountUserSettings. Could you try with the latest version(3.2.2) please? And also you could try to add net logging into your app by adding the code like this into your app.onCreate.

VK.setConfig(VKApiConfig(
            context = this,
            appId = ${your_app_id},
            logger = DefaultApiLogger(lazy { Logger.LogLevel.VERBOSE }, "VKSdkApi"),
            validationHandler = VKDefaultValidationHandler(this)))

Artemych avatar Aug 22 '21 05:08 Artemych

So I can see the json response in log that contains all correct info I need. But function success or fail was not called

AZEY4 avatar Aug 22 '21 12:08 AZEY4

I found out what was wrong. There was AssertionError in Gson.java while result parsing in com.google.code.gson:gson:2.8.6 in your API dependencies. So after I added "com.google.code.gson:gson:2.8.8" in my project all is good now, everything works. I think you should change gson version in your API to 2.8.8

AZEY4 avatar Aug 23 '21 14:08 AZEY4