I am working on a Spring-MVC project in which I am working on Instagram login and pulling other information from Instagram. Currently, the Instagram login part is working quite good, and I get the same access_token back from Instagram whenever I query them. Unfortunately, whenever I call any API's with that token, I get an invalid access_token. What am I doing wrong?
The access_token is of format XXXXX.xxxxx.XXXXXXXX
Login code, controller methods :
org.jinstagram.exceptions.InstagramBadRequestException: OAuthAccessTokenException: The access_token provided is invalid.
at org.jinstagram.entity.common.InstagramErrorResponse.throwException(InstagramErrorResponse.java:45)
at org.jinstagram.Instagram.handleInstagramError(Instagram.java:1187)
at org.jinstagram.Instagram.createInstagramObject(Instagram.java:1131)
at org.jinstagram.Instagram.createInstagramObject(Instagram.java:1150)
at org.jinstagram.Instagram.getCurrentUserInfo(Instagram.java:192)
at com.journaldev.spring.service.HostServiceImpl.pullInstagramMedia(HostServiceImpl.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy69.pullInstagramMedia(Unknown Source)
at com.journaldev.spring.controller.InstagramController.getInstagramPhotos
I don't understand why there is a problem as the access token is what I received from Instagram and I have verified is that's the only one getting used and it is. Any help on this would be nice. thank you.
@RequestMapping(value = "/connectinsta") public String connectToInsta(@RequestParam("student") boolean type,HttpSession session) { session.setAttribute("type",type); return "redirect:https://api.instagram.com/oauth/authorize/?client_id=" + INSTAGRAM_CLIENT_ID + "&redirect_uri=" + INSTAGRAM_REDIRECT_URI + "&response_type=code"; }
@Override public void pullInstagramMedia() { Host host = getCurrentlyAuthenticatedHost(); try { if(host != null){ if((host.isSocialLogin()) && (host.getSocialPlatform().equals("instagram"))) { System.out.println("Host access token is "+host.getAccessToken()); Instagram instagram = new Instagram(host.getAccessToken()); UserInfo userInfo = instagram.getCurrentUserInfo();
I don't understand why there is a problem as the access token is what I received from Instagram and I have verified is that's the only one getting used and it is. Any help on this would be nice. thank you.