1

我正在尝试向朋友发送应用请求,我的代码总是抛出异常,但我看到我的朋友收到了应用请求。我很困惑。有人可以让我知道如何使用 rest-fb api 处理请求对话框吗?

我的代码

     String apprequestCall = "6111349/apprequests"; 
     FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN); 
                        try { 
                                String appRequest = facebookClient.publish(apprequestCall, 
                                                                                                        String.class, 
                                                                                                        Parameter.with("message", "Santhosh"), 
                                                                                                        Parameter.with("data", "Kokala")); 
                        } catch (FacebookJsonMappingException e) { 
                                e.printStackTrace(); 
                        } catch (FacebookException e) { 
                                e.printStackTrace(); 
                        } 
        } 

INFO: 20120505.010030.997 INFO  DefaultWebRequestor - Executing a POST to https://graph.facebook.com/6111349/apprequests with parameters (sent in request body): message=Santhosh&data=Kokala&access_token=ACCESS_TOEKN&format=json

INFO: 20120505.010031.064 WARN  DefaultWebRequestor - An error occurred while POSTing to https://graph.facebook.com/6111349/apprequests
java.io.IOException: Server returned HTTP response code: 403 for URL: https://graph.facebook.com/6111349/apprequests
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1661)
    at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1659)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1657)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1240)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
    at com.restfb.DefaultWebRequestor.executePost(DefaultWebRequestor.java:197)
    at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:428)
    at com.restfb.DefaultFacebookClient.publish(DefaultFacebookClient.java:265)
    at com.restfb.DefaultFacebookClient.publish(DefaultFacebookClient.java:278)
    at com.bitspedia.servlets.AppRequestInvitation.doGet(AppRequestInvitation.java:80)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: https://graph.facebook.com/6111349/apprequests
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1612)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
    ... 31 more

INFO: 20120505.010031.065 INFO  DefaultFacebookClient - Facebook responded with HTTP status code 403 and an empty response body.

WARNING: StandardWrapperValve[AppRequestInvitation]: PWC1406: Servlet.service() for servlet AppRequestInvitation threw exception
com.restfb.FacebookNetworkException: A network error occurred while trying to communicate with Facebook: Facebook POST failed (HTTP status code 403)
    at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:445)
    at com.restfb.DefaultFacebookClient.publish(DefaultFacebookClient.java:265)
    at com.restfb.DefaultFacebookClient.publish(DefaultFacebookClient.java:278)
    at com.bitspedia.servlets.AppRequestInvitation.doGet(AppRequestInvitation.java:80)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)
4

1 回答 1

0

它给出 403 错误,这意味着 Facebook 无法检索/执行您指定的 url。但正如@kitokid 也所说,也提供访问令牌,但不要您的应用程序秘密 ID 放在任何 javascript 中,因为这可以从客户端看到。FB.getloginstatus您可以通过调用或类似函数获得新的访问令牌。

发送邀请可能是因为操作已通过。

于 2012-06-26T13:13:08.823 回答