我正在尝试从Spring启动应用程序连接到twitter。我在我的application.properties文件中添加了appId和appSecret值。但是我得到了一个错误:"'spring.social.twitter.appID‘是一个未知的属性。“
build.gradle文件
buildscript {
ext {
springBootVersion = '2.0.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-
plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'masteringSpringMvc'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.social:spring-social-twitter:1.1.2.RELEASE')
testCompile('org.springframework.boot:spring-boot-starter-test')
}下面是application.properties文件
spring.thymeleaf.cache=false
spring.social.twitter.appID=apiKey
spring.social.twitter.appSecret=appSecret发布于 2018-06-12 19:37:07
使用spring.social.twitter.appId而不是spring.social.twitter.appID (小写“d”)。来源:https://spring.io/guides/gs/accessing-twitter/
发布于 2020-09-15 11:04:55
你也可以使用twitter4j来连接twitter。以下是依赖项步骤:1
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>[3.0,)</version>
</dependency>步骤:2将twitter4j.properties文件添加到您的项目中,然后从twitter APP复制凭据。
oauth.consumerKey=
oauth.consumerSecret=
oauth.accessToken=
oauth.accessTokenSecret=第3步:创建端点
package com.reddit.clone.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
@RestController
@RequestMapping("/twitter")
public class TwitterController {
@RequestMapping(value = "/tweet")
public String getTweets() throws TwitterException {
Twitter twitter = TwitterFactory.getSingleton();
String message = "New Post";
System.out.println(twitter.updateStatus(message).getText());
return "";
}
}https://stackoverflow.com/questions/50816140
复制相似问题