2013-04-24 42 views
-2

我正在編寫一個示例基於Web的應用程序,它要求以XML文檔的形式交付基於圖像的結果。目前我正在使用Picasa搜索API。我正在獲取請求API調用URL的XML響應。 這是我目前的執行:什麼是Picasa Search API的一些不錯的選擇?

private void fetchImageURLs() { 
     try { 
      String urlString = "https://picasaweb.google.com/data/feed/api/all?"; 
      urlString += "q="+searchTerm; 
      urlString += "&max-results="+numImages; 
      urlString += "&start-index="+offset; 

      // Get XML from Picasa API 
      URL url = new URL(urlString); 
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
      DocumentBuilder db = dbf.newDocumentBuilder(); 
      Document doc = db.parse(url.openStream()); 
      doc.getDocumentElement().normalize(); 

      // Parse XML to obtain image URLs 
      NodeList nList = doc.getElementsByTagName("content"); 
      for (int i = 0; i < nList.getLength(); i++) { 
       Node nNode = nList.item(i); 
       Element eElement = (Element) nNode; 
       String imageUrlString = eElement.getAttribute("src"); 

       // Push the image URLs on the queue to be used by fetchImagesAndSave() 
       imageURLs.push(new URL(imageUrlString)); 
      } 
     } 
     catch (Exception e) { 
      e.printStackTrace(); 
     } 
    } 

我會感激,如果你能幫助我搞清楚如何使用Twitter/Facebook的/的photobucket或Flickr API做同樣的。 謝謝。

+1

您應該先嚐試一下。這不是一個網站,旨在讓人們完全爲你完成一項任務(即使有些人是這麼做的)。 – AHungerArtist 2013-04-24 10:01:47

+0

你似乎在這裏問很多。爲什麼不嘗試先尋求幫助,然後尋求具體問題的幫助...... – AngryDuck 2013-04-24 10:09:20

回答

1

爲Flickr:

您可以使用Flickr4Java API。

但因爲所有你需要的是您可以使用REST API搜索:

http://api.flickr.com/services/rest/?method=flickr.test.echo&name=value

你需要的是flicker.photos.search記錄here.

要使用Flickr API的方法,你需要有一個API密鑰雖然,所以你應該apply for one.

0

如果你想使用多個API而不學習每個的具體細節,那麼你應該檢查Temboo

Temboo規範化API訪問,以便使用相同的語法與多個image APIs(以及更多)交談。 Temboo還可以幫助您將API響應轉換爲您選擇的格式(在這種情況下,您可以在適當的情況下將JSON轉換爲XML)。

(全面披露:我在騰博工作)

相關問題