【问题标题】:Issue with Spring boot twitter春季启动推特问题
【发布时间】:2018-06-12 11:34:00
【问题描述】:

我正在尝试从 Spring Boot 应用程序连接到 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

【问题讨论】:

    标签: spring spring-boot model-view-controller


    【解决方案1】:

    使用spring.social.twitter.appId 代替spring.social.twitter.appID(小写“d”)。来源:https://spring.io/guides/gs/accessing-twitter/

    【讨论】:

    • 你收到spring.social.twitter.appId is an unknown property(小写)了吗?
    • 是的,我确实得到了 spring.social.twitter.appId 是未知属性和 spring.social.twitter.appSecret 是未知属性的错误
    • 尝试按照我上面发布的 Spring 教程进行操作。也许你错过了什么
    【解决方案2】:

    您还可以使用 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 "";
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2020-10-23
      • 2021-12-30
      • 2014-01-09
      • 2020-07-02
      • 2018-01-23
      • 2021-08-10
      • 1970-01-01
      • 2016-05-04
      • 2017-12-08
      相关资源
      最近更新 更多