Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yshrsmz/twitter4kt

Twitter API client for KotlIn Multiplatform
https://github.com/yshrsmz/twitter4kt

hacktoberfest kotlin-multiplatform twitter-api

Last synced: 3 months ago
JSON representation

Twitter API client for KotlIn Multiplatform

Awesome Lists containing this project

README

        

twitter4kt
===

Twitter API client for Kotlin Multiplatform Project.

Currently, only available for jvm.

## Setup

### For build.gradle.kts

LATEST_VERSION: `0.2.3`
Twitter4kt is distributed via Maven Central

```kotlin
plugins {
id("org.jetbrains.kotlin.multiplatform") version "1.4.10"
}

repositories {
mavenCentral()
jcenter()
maven(url = "https://kotlin.bintray.com/kotlinx/") // needed for kotlinx-datetime
}

kotlin {
jvm()

sourceSets {
val commonMain by getting {
implementation("com.codingfeline.twitter4kt:core-api:$LATEST_VERSION")
implementation("com.codingfeline.twitter4kt:v1-api:$LATEST_VERSION")

// if you need logging for HTTP calls
implementatin("io.ktor:ktor-client-logging:$KTOR_VERSION")
}
}
}
```

## Usage

```kotlin
val twitter = Twitter {
consumerKeys = ConsumerKeys(
key = "",
secret = ""
)
httpClientConfig = {
install(Logging) {
logger = Logger.SIMPLE
level = LogLevel.ALL
}
}
}

val authFlow = twitter.launchOAuthFlow()

launch(Dispatchers.io) {
val requestToken: RequestToken = authFlow.fetchRequestToken()

val url = requestToken.authorizationUrl
val pinCode = ""

val accessToken = authFlow.fetchAccessToken(requestToken, pinCode)

authFlow.destroy()

val client = twitter.startSession(accessToken)

val result: ApiResult = client.statuses.update(status = "Hello from twitter4kt!")
}
```

## Development

Create `./secrets.properties`

```properties
twitter_consumer_key=
twitter_consumer_secret=
twitter_access_token=
twitter_access_token_secret=
twitter_user_id=
twitter_screen_name=
```

We use these values for testing