无法通过Java从mashape访问gaana API [英] unable to access gaana api via java from mashape
问题描述
我正在使用mashape API试图从Java端访问gaana API
我是从本地主机尝试。但是,我得到的问题,同时试图连接gaana API。
下面是我的休息服务的一个我的code(我用弹簧的安全性和java8)。我BTECH-CSE最后一年的学生。
i am trying to access gaana api from java side by using mashape api i am trying from a localhost. but, i am getting issues while trying to connect gaana api. Below is my code in one of my rest service ( I am using spring-security and java8). I am Btech-CSE final year student.
@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的转换抛出空指针异常。
我热衷于做这个项目。
I need help to proceed in this situation. any kind of help is fine for me. i am getting data as null. so, json conversion is throwing null pointer exception. I am passionate to do this project.
推荐答案
您的数据空
因为你还没有分配 Unirest.get ()
返回值任何东西。
Your data is null
because you haven't assigned the Unirest.get()
return value to anything.
请使用该 API 阅读文档。
这篇关于无法通过Java从mashape访问gaana API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!