Spring 无法通过java从mashape访问gaana api
我试图通过使用mashapeapi从java端访问gaanaapi 我正在本地主机上尝试。但是,我在尝试连接GaanaAPI时遇到了问题。 下面是我的一个rest服务中的代码(我使用的是SpringSecurity和java8)。我是Btech CSE的大四学生Spring 无法通过java从mashape访问gaana api,spring,api,spring-security,mashape,Spring,Api,Spring Security,Mashape,我试图通过使用mashapeapi从java端访问gaanaapi 我正在本地主机上尝试。但是,我在尝试连接GaanaAPI时遇到了问题。 下面是我的一个rest服务中的代码(我使用的是SpringSecurity和java8)。我是Btech CSE的大四学生 @RestController @RequestMapping("/api/ideas") public class IdeaController { @RequestMapping(method = RequestMethod
@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");
}
}
@RestController
@请求映射(“/api/ideas”)
公共类IdeaController{
@RequestMapping(method=RequestMethod.GET)
public void invokeGanaAPI()引发UnirestException{
System.out.println(“你好”);
//这些代码段使用开源库。
//HttpServletResponse=
Unirest.get(“https://community-gaana.p.mashape.com/index.php?subtype=most_popular&type=song")
.header(“X-Mashape-Key”、“iWEvla5JyCmshafdpHdjoSdtPsHPp1Ily4qjsnCEiVxbQsY5tn”)
.header(“接受”、“应用程序/json”)
.asJson();
Unirest.get(“https://community-gaana.p.mashape.com/user.php?type=registrationtoken")
.header(“X-Mashape-Key”、“iWEvla5JyCmshafdpHdjoSdtPsHPp1Ily4qjsnCEiVxbQsY5tn”)
.header(“接受”、“应用程序/json”)
.asJson();
System.out.println(“你好”);
}
}
在这种情况下,我需要帮助才能继续。任何形式的帮助对我都是好的。我得到的数据为空。因此,json转换引发空指针异常。
我热衷于做这个项目 您的数据为
null
,因为您尚未将Unirest.get()
返回值分配给任何对象
请阅读有关使用此函数的文档。您的数据为
null
,因为您尚未将Unirest.get()
返回值分配给任何对象
请阅读有关使用此文件的文档。好的
Unirest.get
没有分配给任何对象,即使您正在以JSON形式检索它。请详细说明。。如何避免它你想完成什么?我对这个项目的摘要是,访问特定用户的GaanaAPI歌曲列表。这样我就可以根据用户的兴趣进行分析并提供建议。@Geditdk您的重复链接指向这个问题。Unirest.get
没有分配给任何东西,即使您是以JSON的形式检索它。您能详细说明一下吗。。如何避免它你想完成什么?我对这个项目的摘要是,访问特定用户的GaanaAPI歌曲列表。这样我就可以根据用户的兴趣进行分析并提供建议。@Geditdk您的重复链接指向这个问题。