簡體   English   中英

在獲取Facebook數據時,它會引發Facebook網絡異常和java.net.MalformedURLException:無協議:我/提要?

[英]While fetching facebook data it throws facebook network exception and java.net.MalformedURLException: no protocol: me/feed?

Exception in thread "main" com.restfb.exception.FacebookNetworkException: A network error occurred while trying to communicate with Facebook: Facebook request failed (HTTP status code null)
    at 
 com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookC
  lient.java:1024)
    at 
 com.restfb.DefaultFacebookClient.fetchConnectionPage(DefaultFacebookClient.java
    :374)
    at main.main(main.java:26)

    Caused by: java.net.MalformedURLException: no protocol: me/feed
    at java.net.URL.<init>(URL.java:585)
    at java.net.URL.<init>(URL.java:482)
    at java.net.URL.<init>(URL.java:431)
    at com.restfb.DefaultWebRequestor.execute(DefaultWebRequestor.java:365)
    at com.restfb.DefaultWebRequestor.executeGet(DefaultWebRequestor.java:96)
    at 

  com.restfb.DefaultFacebookClient$2.makeRequest(DefaultFacebookClient.java:377)
    at 
 com.restfb.DefaultFacebookClient.makeRequestAndProcessResponse(DefaultFacebookC
   lient.java:1022)
    ... 2 more

   Java Result: 1
   BUILD SUCCESSFUL (total time: 0 seconds)

當我嘗試在請求中發送的user_posts不能正確發送時,這是我的錯誤。 如何解決呢?

    /*
    * To change this license header, choose License Headers in Project
    Properties.
    * To change this template file, choose Tools | Templates
    * and open the template in the editor.
    */

    /**
    *
    * @author User
    */
    import com.restfb.Connection;
    import com.restfb.DefaultFacebookClient;
    import com.restfb.FacebookClient;
    import com.restfb.types.Post;
    import java.util.*;

    public class main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String accesstoken="EAACEdEose0cBAAXB6i9nmi0VJSZCHI******************";        
        FacebookClient fbclient=new DefaultFacebookClient(accesstoken);
        Connection<Post> result=fbclient.fetchConnectionPage("me/feed", 
                                                               Post.class);        
        int counter=0;

        for(List<Post>page : result)
        {
         for(Post aPost:page)
         {
          System.out.println(aPost.getMessage());
          System.out.print(aPost.getId());
          counter++;        
         }
        }
        System.out.println(" counter "+counter);

    }

   }

在此代碼中,訪問令牌是從Developer選項獲得的。

根據用於fetchConnectionPage的RestFB API( http://restfb.com/javadoc-2/com/restfb/DefaultFacebookClient.html#fetchConnectionPage-java.lang.String-java.lang.Class- ),您需要傳遞正確的URL 。

所以基本上在這條線上:

Connection<Post> result=fbclient.fetchConnectionPage("me/feed", Post.class);

而不是傳遞“ me / feed”,您需要傳遞一個完整的URL,例如“ http://facebook.com/me/feed ”或該URL應該是任何URL。

MalformedURLException也向您暗示了這一點,因為您傳遞的應該是URL。 這表明您沒有提供正確的網址。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM