我正在尝试从本地主机使用mashape api从java端访问gaana api。但是,我在尝试连接gaana api时遇到问题。下面是我的一个rest服务中的代码(我使用了spring-security和java8)。我是Btech-CSE的大四学生。
@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");
}
}我需要帮助才能处理这种情况。任何形式的帮助对我来说都没问题。我获取的数据为null。所以,json转换抛出了空指针异常。我很热衷于做这个项目。
发布于 2016-03-06 15:00:46
您的数据是null,因为您还没有将Unirest.get()返回值赋给任何对象。
请阅读有关使用此API的文档。
https://stackoverflow.com/questions/35818086
复制相似问题