2012-08-16 39 views
4

我是使用Goolge API開發的新手。我正在嘗試使用C#工作的Google.Apis.Freebase.V1 API。有沒有人有一個在C#中使用這個API的小例子?我花了最近幾天的時間,只能找到一些舊的Freebase Api的例子。 Google API沒有任何作用。Google Freebase Api C#.Net示例

我只是尋找一個簡單的例子來建立一個連接到API,做一個搜索,然後如何處理一個MQL查詢返回到一個Json對象。越簡單越好。

感謝 斯科特

回答

3

正確的代碼使用Google API Client Library應該是這個樣子做一個MQL查詢在C#:

string API_KEY = "your-api-key-here"; 
FreebaseService service = new FreebaseService{ Key = API_KEY }; 
String query = "[{\"id\":null,\"name\":null,\"type\":\"/astronomy/planet\"}]"; 
FreebaseService.MqlreadRequest request = service.Mqlread(query); 
string response = request.Fetch(); 
Console.WriteLine (response); 

遺憾的是,似乎有某種錯誤與客戶端因爲它沒有返回任何結果。我會試着弄清楚那裏發生了什麼。

更新:問題似乎是客戶端庫傳遞了Freebase API無法支持的alt = json參數。 Python客戶端庫有一種方法可以禁用此功能,但無法在.Net中執行。您可以在Google Code項目上關注the open bug

+0

謝謝,那就是我一直在尋找的。結果問題解決後請更新。 – Scott 2012-08-21 04:32:19