Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dittos committed Jul 3, 2018
1 parent 393eb41 commit 8f89ef1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dependencies {
compile "org.springframework.boot:spring-boot-starter-data-jpa"
compile "org.springframework.boot:spring-boot-starter-web"
providedRuntime "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.springframework.social:spring-social-twitter:1.1.0.RELEASE"
compile "org.springframework.social:spring-social-twitter:2.0.0.M4"
compile "org.springframework.cloud:spring-cloud-gcp-starter-storage:1.0.0.M2"
compile "io.sentry:sentry-logback:1.7.1"
compile "com.fasterxml.jackson.module:jackson-module-kotlin"
Expand Down
3 changes: 2 additions & 1 deletion backend/src/main/kotlin/net/animeta/backend/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import net.animeta.backend.security.CurrentUserArgumentResolver
import net.animeta.backend.serializer.PostSerializer
import net.animeta.backend.serializer.RecordSerializer
import net.animeta.backend.serializer.UserSerializer
import net.animeta.backend.social.TwitterServiceProvider2
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.SpringApplication
Expand Down Expand Up @@ -48,7 +49,7 @@ class Application : SpringBootServletInitializer() {
@Bean
fun twitterServiceProvider(@Value("\${spring.social.twitter.app-id}") appId: String,
@Value("\${spring.social.twitter.app-secret}") appSecret: String): TwitterServiceProvider {
return TwitterServiceProvider(appId, appSecret)
return TwitterServiceProvider2(appId, appSecret)
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.animeta.backend.social

import org.springframework.social.twitter.api.Twitter
import org.springframework.social.twitter.connect.TwitterServiceProvider

class TwitterServiceProvider2(consumerKey: String, consumerSecret: String) : TwitterServiceProvider(consumerKey, consumerSecret) {

override fun getApi(accessToken: String, secret: String): Twitter {
return TwitterTemplate2(consumerKey, consumerSecret, accessToken, secret)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.animeta.backend.social

import org.springframework.http.MediaType
import org.springframework.http.client.ClientHttpRequestInterceptor
import org.springframework.social.twitter.api.impl.TwitterTemplate
import org.springframework.web.client.RestTemplate

class TwitterTemplate2(a: String, b: String, c: String, d: String) : TwitterTemplate(a, b, c, d) {
override fun configureRestTemplate(restTemplate: RestTemplate) {
super.configureRestTemplate(restTemplate)
restTemplate.interceptors.add(0, ClientHttpRequestInterceptor { request, body, execution ->
request.headers.contentType = MediaType.APPLICATION_FORM_URLENCODED
execution.execute(request, body)
})
}
}

0 comments on commit 8f89ef1

Please sign in to comment.