2017-05-02 39 views
0

我在訪問URL時收到了java.net.unknownhostexception,但我可以通過瀏覽器訪問。訪問graph.facebook.com時出現未知主機異常

 public static void main(String[] args) throws IOException, JSONException`enter code here` 
{ 
JSONObject json = readJsonFromUrl("https://graph.facebook.com/page_id/? 
access_token=xxxxx&fields=name,likes,posts"); 
System.out.println(json.toString()); 
System.out.println(json.get("likes")); 
} 

回答

1

您使用的請求URL無效。在您的請求網址中,將page_id更改爲您要請求數據的實際Facebook頁面ID,幷包含您正在使用的API版本。

E.g.如果我想訪問一個頁面的ID爲3454546 -

https://graph.facebook.com/v2.9/3454546?access_token=xxxxx&fields=name,likes,posts