토큰받아서 API사용중에 에러나서요ㅠㅠㅠㅠ

기본소스.

 

<p><%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import = "com.restfb.exception.FacebookOAuthException" %>
<%@ page import = "com.restfb.Parameter" %>
<%@ page import = "com.restfb.types.FacebookType" %>
<%@ page import = "com.restfb.DefaultFacebookClient" %>
<%@ page import = "java.util.List" %>
<%@ page import = "com.restfb.types.User" %>
<%
String accesstoken = "CAACxGO06MiUBAEFUsjdbfwNdkXoanjSgcAuXlIZB6Wy4TDW5meN3QHAZANoRPRIfeoIHgmy5JF7O2Gma0ndJWDiZCFZC4C8rutLlgwUA45XoKKi0dMCdLj1OiYEbCdKo07oRbpWQ2aBXc0ZAXGqFqBKrJ5B1YZBPYZD&expires=5177265";
DefaultFacebookClient fbClient = new DefaultFacebookClient(accesstoken);

List<User> friends = null;
try{
friends = fbClient.fetchConnection("me/friends", User.class).getData();
}catch(FacebookOAuthException e){
e.printStackTrace();
}
%>
< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html>
< head>
< meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
< title>Insert title here</title>
< /head>
< body>
친구의 수: <%=friends.size() %>
< /body>
< /html>
< /p>

 

 

 

-------------------------------------------------에러---------------------------------------------

com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: Malformed access token CAACxGO06MiUBAEFUsjdbfwNdkXoanjSgcAuXlIZB6Wy4TDW5meN3QHAZANoRPRIfeoIHgmy5JF7O2Gma0ndJWDiZCFZC4C8rutLlgwUA45XoKKi0dMCdLj1OiYEbCdKo07oRbpWQ2aBXc0ZAXGqFqBKrJ5B1YZBPYZD&expires=5177265
at com.restfb.DefaultFacebookClient$DefaultGraphFacebookExceptionMapper.exceptionForTypeAndMessage(DefaultFacebookClient.java:766)
at com.restfb.DefaultFacebookClient.throwFacebookResponseStatusExceptionIfNecessary(DefaultFacebookClient.java:688)
at com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookClient.java:630)
at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:592)
at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:556)
at com.restfb.DefaultFacebookClient.fetchConnection(DefaultFacebookClient.java:219)
at org.apache.jsp.face3_jsp._jspService(face3_jsp.java:73)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
2013. 5. 22 오후 6:24:05 org.apache.catalina.core.StandardWrapperValve invoke
심각: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.face3_jsp._jspService(face3_jsp.java:87)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)

--------------------------------------------------------------------------------------------------대충 해석을 해보았습니다. 위에 검은색 글씨의 에러부분은 트라이 캐치에서 찍어낸 에러입니다.

 

해석을 해보면. 받아온 accessToken이 잘못 되었다는 뜻 같습니다..(위,보라색부분)

 

그래서 다시 로그인 인증을 통해 accessToken을 다시 받고 새로운 토큰을 넣고 돌려보았는데도

 

계속 저 에러가 나더군요.. 그렇기에 토큰이 잘못되어 아래 널포인트를 야기 시키는것같습니다..

 

로그인 인증으로 인해 얻은 토큰의 사용법이 잘못되었을까요?

 

왜 저렇게 에러가 날까요..??

 

 

-----------------------------------------------------------------------------------------------

<%@ page language = "java" contentType ="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<%@ page import = "java.net.*" %>
<%
String appID = "194720617345573";
String callbackUrl = "http://192.168.1.119:9090/face/face2.jsp";
String oauthUrl = "https://www.facebook.com/dialog/oauth?" +
"client_id="+appID+"&redirect_uri="+URLEncoder.encode(callbackUrl, "UTF-8")+
"&scope=user_about_me, publish_stream, read_friendlists, offline_access";;
response.sendRedirect(oauthUrl);
%>

 

-------------------------------------------------------------------------------------------------

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import = "java.net.*, java.io.*" %>
<%
String code = request.getParameter("code");
String appID = "194720617345573";
String appSecret = "692ea36ea932c472383c5746891b27b1";
String callbackUrl = "http://192.168.1.119:9090/face/face2.jsp";
String access_token_url = "https://graph.facebook.com/oauth/access_token?"
+"client_id="+appID
+"&redirect_uri="+URLEncoder.encode(callbackUrl, "UTF-8")
+"&client_secret="+appSecret+"&code="+code;

URL yahoo = new URL(access_token_url);
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
/* HttpURLConnection httpConn = (HttpURLConnection)yc;
InputStream is;
if(httpConn.getResponseCode() >= 400){
is = httpConn.getErrorStream();
}else{
is = httpConn.getErrorStream();
} */
String inputLine = null;
out.println("<br/>access_token respons=======================================");
while((inputLine = in.readLine()) != null)
out.println(inputLine);
out.println("<br/>access_token respons=======================================");
in.close();
%>
<br />code:<%=code %> <br />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>

</body>
</html>

 

--------------------------------------------------위에 두개가 토큰을 받아오는.. jsp입니당..

워드프레스 에러 기술지원 서비스 전문가에게 맡기세요
좋은 정보와 인맥을 동시에, 워드프레스 사용자 단톡방 참여하기
워드프레스 에러 기술지원 서비스 전문가에게 맡기세요