1
我想通過使用mashape api訪問來自java端的gaana api 我想從本地主機上嘗試。但是,我在嘗試連接gaana api時遇到問題。 下面是我的其中一個休息服務(我正在使用spring-security和java8)的代碼。我是Btech-CSE最後一年的學生。無法通過從mashape java訪問gaana api
@RestController
@RequestMapping("/api/ideas")
public class IdeaController {
@RequestMapping(method = RequestMethod.GET)
public void invokeGaanaAPI() throws UnirestException {
System.out.println("hello");
// These code snippets use an open-source library.
// HttpServletResponse<JsonNode> response =
Unirest.get("https://community-gaana.p.mashape.com/index.php?subtype=most_popular&type=song")
.header("X-Mashape-Key", "iWEvla5JyCmshafdpHdjoSdtPsHPp1Ily4qjsnCEiVxbQsY5tn")
.header("Accept", "application/json")
.asJson();
Unirest.get("https://community-gaana.p.mashape.com/user.php?type=registrationtoken")
.header("X-Mashape-Key", "iWEvla5JyCmshafdpHdjoSdtPsHPp1Ily4qjsnCEiVxbQsY5tn")
.header("Accept", "application/json")
.asJson();
System.out.println("hello");
}
}
我需要幫助來處理這種情況。任何形式的幫助都適合我。我得到的數據爲空。所以,json轉換就是拋出空指針異常。 我熱衷於做這個項目。
那麼'Unirest.get'沒有分配給任何東西,即使你正在將它作爲JSON檢索。 – dkanejs
可以請您詳細說明..如何避免它 –
你試圖完成什麼? – dkanejs