1

我正在使用嘗試向朋友發送應用請求,我的代碼總是拋出異常但我看到我的朋友獲得應用請求。我是 困惑。有人可以讓我知道使用rest-fb api來處理請求對話框嗎?Facebook:POST userid/apprequest拋出一個異常(儘管發送了邀請)

我的代碼

 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) 
+0

嗨,你可以試用一下accesstoken,用戶在原始流程中授予應用程序嗎?而不是通過字符串創建的訪問標記tokenUrl =「https://graph.facebook.com/oauth/access_token?client_id=」+ appId +「&client_secret =」+ appSecret +「&grant_type = client_credentials」; – kitokid

+0

當我檢查你的第一個鏈接時,我遇到了同樣的情況.http://stackoverflow.com/questions/6072839/facebook-send-an-app-invitation/8225243#8225243。謝謝。 – kitokid

回答

0

這是給403錯誤,這意味着Facebook是無法檢索/執行您指定的URL。但正如@kitokid也表示,提供accesstoken以及,但donot把你的應用程序的祕密id在任何JavaScript,從客戶端可以看出。你可以通過撥打FB.getloginstatus或類似的功能獲得一個新的訪問權限。

邀請被髮送可能是因爲該操作已經過。