I'm trying to build a tasks app which makes use of the google tasks API. I have activated it on my google cloud console and managed to log into my google account through my app.
Now that I'm trying to use the google tasks API, the compiler isn't recognising the services package required for com.google.api.services.tasks.Tasks. As I've been unable to find any relevant documentation for using the API with kotlin in android studio, I've been using ChatGPT as a coding aid which seems adamant that the package should exist.
Here is the relevant task API code so far:
import com.google.android.gms.auth.api.signin.GoogleSignInAccount
import com.google.android.gms.tasks.Tasks
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential
import com.google.api.client.http.javanet.NetHttpTransport
import com.google.api.client.json.gson.GsonFactory
import com.google.api.services.tasks.Tasks
//other imports...
class GoogleTasksManager(private val context: Context) {
private lateinit var tasksService: Tasks
// Link to Google account
private var googleAccount: GoogleSignInAccount? = null
// Set Google account
fun setGoogleAccount(account: GoogleSignInAccount?) {
googleAccount = account
account?.let { setupTasksService(it) }
}
// Get Google account
fun getGoogleAccount(): GoogleSignInAccount? {
return googleAccount
}
private fun setupTasksService(account: GoogleSignInAccount) {
val credential = GoogleAccountCredential.usingOAuth2(
context,
listOf("https://www.googleapis.com/auth/tasks")
)
credential.selectedAccount = account.account
// Create the Google Tasks API client
val transport = NetHttpTransport()
val jsonFactory = GsonFactory.getDefaultInstance()
tasksService = Tasks.Builder(transport, jsonFactory, credential)
.setApplicationName("TasksListHub")
.build()
}
}
I believe I have included the relevant dependencies in my module-level build.gradle.kts:
implementation("com.google.apis:google-api-services-tasks:v1-rev20230911-1.32.1")
implementation("com.google.api-client:google-api-client-android:1.33.0")
implementation("com.google.api-client:google-api-client-gson:1.33.0")
... and in my project-level build.gradle.kts:
buildscript {
dependencies {
classpath("com.google.gms:google-services:4.4.2")
}
}
plugins {
id("com.google.gms.google-services") version "4.4.2" apply false
//other plugins...
}
I'm new to android development and kotlin so any help would be greatly appreciated. Thanks
Turns out the dependency "com.google.apis:google-api-services-tasks:v1-rev20230911-1.32.1" should be "com.google.apis:google-api-services-tasks:v1-rev71-1.25.0"
Found the relevant documentation and dependencies here: https://mvnrepository.com/artifact/com.google.apis/google-api-services-tasks/v1-rev71-1.25.0
and here: https://developers.google.com/resources/api-libraries/documentation/tasks/v1/java/latest/
Hope this helps anyone with the same problem.