[英]Spring Social-Java application for accessing LinkedIn data
我正在使用Java和Spring Social作為Maven項目開發一個Twitter應用程序。 當我運行代碼時,它顯示以下異常!
我的Java零件代碼
應用程序
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {
/*
* SPRING BOOTSTRAP MAIN
*/
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
HelloCantroller.java
package hello;
import java.util.List;
import javax.inject.Inject;
import org.springframework.social.connect.UserProfile;
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 HelloController {
private LinkedIn linkedin;
UserProfile userProfile;
@Inject
public HelloController(LinkedIn linkedin) {
this.linkedin = linkedin;
}
@RequestMapping(method=RequestMethod.GET)
public String helloLinkedIn(Model model) {
if (!linkedin.isAuthorized()) {
return "redirect:/connect/linkedin";
}
LinkedInProfile profile = linkedin.profileOperations().getUserProfile();
String profileId = linkedin.profileOperations().getProfileId();
System.out.println(profileId);
return "hello";
}
}
HTML頁面
LinkedinConnect.html
<html>
<head>
<title>Hello LinkedIn</title>
</head>
<body>
<h3>Connect to LinkedIn</h3>
<form action="/connect/linkedin" method="POST">
<!-- <input type="hidden" name="scope" value="read_stream" /> -->
<div class="formInfo">
<p>You aren't connected to LinkedIn yet. Click the button to connect this application with your Facebook account.</p>
</div>
<p><button type="submit">Connect to Facebook</button></p>
</form>
</body>
</html>
LinkedInConnected.html
<html>
<head>
<title>Hello Facebook</title>
</head>
<body>
<h3>Connected to Facebook</h3>
<p>
You are now connected to your Facebook account.
Click <a href="/">here</a> to see some entries from your Facebook home feed.
</p>
</body>
</html>
如何解決上述錯誤並使我的代碼可運行?
在LinkedinConnect.html中取消注釋輸入type =“ hidden” name =“ scope” value =“ read_stream”,因為模型將引用值read_stream引用的地圖對象
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.