VK.execute(AccountService().accountGetProfileInfo(), object : VKApiCallback<AccountUserSettings> does not work
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?
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)))
So I can see the json response in log that contains all correct info I need. But function success or fail was not called
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