반응형
1. 다음 종속성을 pom.xml 파일에 추가합니다.
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-instagram</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-social-instagram</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
2. application.properties 파일에 Instagram Client ID 및 Client Secret 추가
spring.social.instagram.app-id=YOUR_CLIENT_ID
spring.social.instagram.app-secret=YOUR_CLIENT_SECRET
3. Instagram Connect 컨트롤러 구현
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.social.connect.web.ConnectController;
import org.springframework.stereotype.Controller;
@Controller
public class InstagramConnectController extends ConnectController {
public InstagramConnectController(ConnectionFactoryLocator connectionFactoryLocator,
ConnectionRepository connectionRepository) {
super(connectionFactoryLocator, connectionRepository);
}
}
4. Instagram 로그인 만들기
<a href="<c:url value='/connect/instagram' />">Login with Instagram</a>
5. 콜백 엔드포인트 구현
import org.springframework.social.connect.Connection;
import org.springframework.social.connect.web.ProviderSignInUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
@Controller
public class InstagramCallbackController {
private final ProviderSignInUtils providerSignInUtils;
public InstagramCallbackController(ProviderSignInUtils providerSignInUtils) {
this.providerSignInUtils = providerSignInUtils;
}
@RequestMapping(value = "/instagram")
public String instagram(HttpServletRequest request) {
Connection<?> connection = providerSignInUtils.getConnectionFromSession(request);
// store the user's data in your database
// redirect the user to the appropriate page
return "redirect:/";
}
}
반응형
'Spring Boot' 카테고리의 다른 글
[Google API + Springboot] Gmail 록록 취득하기 (0) | 2023.02.08 |
---|---|
[Springboot] Instagram 사진 올리기 연동 구현(인스타그램 + java) (0) | 2023.02.08 |
[Springboot] Facebook 로그인 연동 구현 (0) | 2023.02.08 |
[Springboot] smtp email 보내기 구현 (0) | 2023.02.08 |
[Google API + Springboot] 유튜브 영상올리기 (Google youtube) 구현 소스 (0) | 2023.02.08 |