2016-07-20 13 views
1


Bitte auf diese Frage antworten, entwickle ich eine Feder Boot-Anwendung, die LinkedIn-Daten zugreift, aber wenn ich auf klicken von „http://localhost:8080/connect/linkedin“, um die URL ändern „zu linkedIn verbinden“ zu "http://localhost:8080/connect/linkedin#!"Frühling Boot-Anwendung für den Zugriff auf LinkedIn Daten

LinkedInController.java

Paket 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> 

Antwort

0

Projektverzeichnisstruktur

Project Directory Structure

-Controller

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

Seiten