2012-04-15 49 views
0

我正在尝试开发一个在Facebook中搜索的应用程序。 问题是,当使用阿拉伯语单词进行搜索时,我得到了不正确的结果(非阿拉伯文帖子) 我试图在使用以下编码将其传递到搜索URL之前对其进行编码(UTF-8,ISO-8859-6和Windows-1256),结果会改变,但仍然不正确。在Facebook上通过阿拉伯语字词搜索usig facebook图表API

以下是我使用的Java代码:

public JSONObject search(String strSearchPhrase, String strType) throws MalformedURLException, IOException { 

    strSearchPhrase = URLEncoder.encode(strSearchPhrase, "ISO-8859-6"); 

    URL searchURL = new URL("https://graph.facebook.com/search?q=" + strSearchPhrase + "&type=" + strType + "&access_token=" + strAccessToken); 

    URLConnection urlCon = searchURL.openConnection(); 

    BufferedReader buffReader = new BufferedReader(new InputStreamReader(urlCon.getInputStream())); 

    String strInputLine; 

    String strOutput = ""; 

    while ((strInputLine = buffReader.readLine()) != null) { 
     strOutput = strOutput + strInputLine; 
    } 
    buffReader.close(); 
    Object objOutput = JSONValue.parse(strOutput); 
    JSONObject jsonOutput = (JSONObject)objOutput; 

    //return data; 
    return jsonOutput; 
} 

它正常工作与英语,但不与阿拉伯

任何帮助或想法可以理解

+0

如果您发布您用于搜索的代码,这将有所帮助。 – 2012-04-15 13:10:50

+0

现在已添加代码 – 2012-04-15 14:26:20

回答

0

我不知道,我试过这个:

curl "https://graph.facebook.com/search?q=محمود‎&type=user&access_token=xxxx" 

它看起来好像工作正常,所有的结果我在哪里n这个形式: “\ u0645 \ u062d \ u0645 \ u0648 \ u062f”

当我试试这个:

curl "https://graph.facebook.com/search?q=bob&type=user&access_token=xxxx" 

结果有定期的英文字符。

我在想,也许你的编码是出了什么问题,也许尝试:

URL searchURL = new URL("https://graph.facebook.com/search?q=محمود‎&type=" + strType + "&access_token=" + strAccessToken); 

这就是一个硬编码阿拉伯串入网址,检查工程。

+0

感谢您的关心,但结果不幸是不正确的。你可以打开这个配置文件,这是第一个结果https://www.facebook.com/100001552568248 – 2012-04-15 15:33:26

+0

第一个结果是什么?我不懂阿拉伯语,所以我不确定你的意思。 – 2012-04-15 15:38:24

+0

您的搜索网址搜索名为“محمود”的人,但搜索结果中不包含此名称,这表示搜索无法正常工作,谢谢 – 2012-04-15 15:52:18