【问题标题】:Spring boot application for accessing LinkedIn data用于访问 LinkedIn 数据的 Spring Boot 应用程序
【发布时间】:2016-07-20 10:09:55
【问题描述】:


请回答这个问题,我开发了一个访问 LinkedIn 数据的 Spring Boot 应用程序,但是当我单击“connect to linkedIn”按钮时,URL 会从“http://localhost:8080/connect/linkedin”更改到“http://localhost:8080/connect/linkedin#!

LinkedInController.java

包 com.linkedIn;

import javax.inject.Inject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.social.connect.ConnectionRepository;

import org.springframework.social.linkedin.api.LinkedIn;
import org.springframework.social.linkedin.api.LinkedInProfile;
import org.springframework.social.linkedin.api.impl.LinkedInTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/")
public class LinkedInController {

    private LinkedIn linkedIn;
    private ConnectionRepository connectionRepository;

    @Inject
    public LinkedInController(LinkedIn linkedIn, ConnectionRepository connectionRepository) {
        this.linkedIn = linkedIn;
        this.connectionRepository = connectionRepository;
    }

    @RequestMapping(method = RequestMethod.GET)
    public String helloLinkedIn(Model model) {
        if (connectionRepository.findPrimaryConnection(LinkedIn.class) == null) {
            return "redirect:/connect/linkedin";
        }
        LinkedInProfile linkedInProfile = linkedIn.profileOperations().getUserProfile();
        model.addAttribute("linkedInProfile", linkedInProfile);
        return "hello";
    }
}

\src\main\resources\templates\connect\linkedinConnect.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="ISO-8859-1"></meta>
        <title>Hello LinkedIn</title>
    </head>
    <body>
        <h3>Connect to LinkedIn</h3>

        <form action="/connect/linkedin" method="POST">
            <input type="hidden" name="scope" value="user_posts" />
            <div class="formInfo">

                <p>You aren't connected to LinkedIn yet. Click the button to
                    connect this application with your LinkedIn account.</p>
            </div>
            <button type="submit">Connect to LinkedIn</button>      
        </form>
    </body>
</html>

【问题讨论】:

    标签: java spring spring-boot linkedin


    【解决方案1】:

    项目目录结构

    控制器

    package com.linkedIn.controller;

    import org.springframework.social.connect.ConnectionRepository; import org.springframework.social.linkedin.api.LinkedIn; import org.springframework.social.linkedin.api.ProfileOperations; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping;

    @Controller

    @RequestMapping("/linkedin")

    public class LinkedInController {

    `private LinkedIn linkedIn;`
    
    `private ConnectionRepository connectionRepository;`
    
    
    public LinkedInController(LinkedIn linkedIn, ConnectionRepository connectionRepository) {
        this.linkedIn = linkedIn;
        this.connectionRepository = connectionRepository;
    }
    
    @GetMapping
    public String helloLinkedIn(Model model) {
        if (connectionRepository.findPrimaryConnection(LinkedIn.class) == null) {
            return "redirect:/connect/linkedin";
        }
        // ProfileOperations user = linkedIn.profileOperations();
        model.addAttribute("linkedInProfile", linkedIn.profileOperations().getUserProfileFull());
        return "linkedin";
    }
    

    }

    springboot-linkedin-apply Github Project

    页面

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-27
      • 1970-01-01
      • 2021-06-22
      • 2017-09-01
      • 2015-07-17
      • 1970-01-01
      • 2023-01-12
      • 2021-12-03
      相关资源
      最近更新 更多