地区新闻
请求Header:
| 名称 | 值 | |
|---|---|---|
| Content-Type | application/x-www-form-urlencoded |
请求参数说明:
| 名称 | 必填 | 类型 | 说明 | |
|---|---|---|---|---|
| key | 是 | string | 您在聚合平台申请的接口凭证(可在个人中心进行查看) | |
| areaname | 是 | string | 地区名,不要带“省”或“市” | |
| word | 否 | string | 搜索某地区下的新闻关键词 | |
| page | 否 | int | 翻页 |
请求代码示例:
curl -k -i "https://apis.juhe.cn/fapigx/areanews/query?key=key&areaname=xxx&word=&page=20"
<?php
/**
* 1786-地区新闻 - 代码参考(根据实际业务情况修改)
*/
// 基本参数配置
$apiUrl = "https://apis.juhe.cn/fapigx/areanews/query"; // 接口请求URL
$method = "GET"; // 接口请求方式
$headers = ["Content-Type: application/x-www-form-urlencoded"]; // 接口请求header
$apiKey = "您申请的调用APIkey"; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
$requestParams = [
'key' => $apiKey,
'areaname'=> 'xxx',
'word'=> '',
'page'=> '20',
];
$requestParamsStr = http_build_query($requestParams);
// 发起接口网络请求
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $apiUrl . '?' . $requestParamsStr);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if (1 == strpos("$" . $apiUrl, "https://")) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$response = curl_exec($curl);
$httpInfo = curl_getinfo($curl);
curl_close($curl);
// 解析响应结果
$responseResult = json_decode($response, true);
if ($responseResult) {
// 网络请求成功。可依据业务逻辑和接口文档说明自行处理。
var_dump($responseResult);
} else {
// 网络异常等因素,解析结果异常。可依据业务逻辑自行处理。
// var_dump($httpInfo);
var_dump("请求异常");
}
import requests
# 1786-地区新闻 - 代码参考(根据实际业务情况修改)
# 基本参数配置
apiUrl = 'https://apis.juhe.cn/fapigx/areanews/query' # 接口请求URL
apiKey = '您申请的调用APIkey' # 在个人中心->我的数据,接口名称上方查看
# 接口请求入参配置
requestParams = {
'key': apiKey,
'areaname': 'xxx',
'word': '',
'page': '20',
}
# 发起接口网络请求
response = requests.get(apiUrl, params=requestParams)
# 解析响应结果
if response.status_code == 200:
responseResult = response.json()
# 网络请求成功。可依据业务逻辑和接口文档说明自行处理。
print(responseResult)
else:
# 网络异常等因素,解析结果异常。可依据业务逻辑自行处理。
print('请求异常')
package main
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
)
func main() {
// 基本参数配置
apiUrl := "https://apis.juhe.cn/fapigx/areanews/query"
apiKey := "您申请的调用APIkey"
// 接口请求入参配置
requestParams := url.Values{}
requestParams.Set("key", apiKey)
requestParams.Set("areaname", "xxx")
requestParams.Set("word", "")
requestParams.Set("page", "20")
// 发起接口网络请求
resp, err := http.Get(apiUrl + "?" + requestParams.Encode())
if err != nil {
fmt.Println("网络请求异常:", err)
return
}
defer resp.Body.Close()
var responseResult map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&responseResult)
if err != nil {
fmt.Println("解析响应结果异常:", err)
return
}
fmt.Println(responseResult)
}
using System;
using System.Net;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
namespace Common_API_Test.Test_Demo
{
class Csharp_get
{
static void Main(string[] args)
{
string url = "https://apis.juhe.cn/fapigx/areanews/query";
string apiKey = "您申请的调用APIkey";
Dictionary<string, string> data = new Dictionary<string, string>();
data.Add("key", apiKey);
data.Add( "areaname", "xxx");
data.Add( "word", "");
data.Add( "page", "20");
using (WebClient client = new WebClient())
{
string fullUrl = url + "?" + string.Join("&", data.Select(x => x.Key + "=" + x.Value));
try
{
string responseContent = client.DownloadString(fullUrl);
dynamic responseData = JsonConvert.DeserializeObject(responseContent);
if (responseData != null)
{
Console.WriteLine("Return Code: " + responseData["error_code"]);
Console.WriteLine("Return Message: " + responseData["reason"]);
}
else
{
Console.WriteLine("json解析异常!");
}
}
catch (Exception)
{
Console.WriteLine("请检查其它错误");
}
}
}
}
}
const axios = require('axios'); // npm install axios
// 基本参数配置
const apiUrl = 'https://apis.juhe.cn/fapigx/areanews/query'; // 接口请求URL
const apiKey = '您申请的调用APIkey'; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
const requestParams = {
key: apiKey,
areaname: 'xxx',
word: '',
page: '20',
};
// 发起接口网络请求
axios.get(apiUrl, {params: requestParams})
.then(response => {
// 解析响应结果
if (response.status === 200) {
const responseResult = response.data;
// 网络请求成功。可依据业务逻辑和接口文档说明自行处理。
console.log(responseResult);
} else {
// 网络异常等因素,解析结果异常。可依据业务逻辑自行处理。
console.log('请求异常');
}
})
.catch(error => {
// 网络请求失败,可以根据实际情况进行处理
console.log('网络请求失败:', error);
});
package cn.juhe.test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class JavaGet {
public static void main(String[] args) throws Exception {
String apiKey = "你申请的key";
String apiUrl = "https://apis.juhe.cn/fapigx/areanews/query";
HashMap<String, String> map = new HashMap<>();
map.put("key", apiKey);
map.put("areaname", "xxx");
map.put("word", "");
map.put("page", "20");
URL url = new URL(String.format("%s?%s", apiUrl, params(map)));
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response);
}
public static String params(Map<String, String> map) {
return map.entrySet().stream()
.map(entry -> {
try {
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString());
} catch (Exception e) {
e.printStackTrace();
return entry.getKey() + "=" + entry.getValue();
}
})
.collect(Collectors.joining("&"));
}
}
// 基本参数配置
NSString *apiUrl = @"https://apis.juhe.cn/fapigx/areanews/query"; // 接口请求URL
NSString *apiKey = @"您申请的调用APIkey"; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
NSDictionary *requestParams = @{
@"key": apiKey,
@"areaname": @"xxx",
@"word": @"",
@"page": @"20",
};
// 发起接口网络请求
NSURLComponents *components = [NSURLComponents componentsWithString:apiUrl];
NSMutableArray *queryItems = [NSMutableArray array];
[requestParams enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) {
[queryItems addObject:[NSURLQueryItem queryItemWithName:key value:value]];
}];
components.queryItems = queryItems;
NSURL *url = components.URL;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
// 网络请求异常处理
NSLog(@"请求异常");
} else {
NSError *jsonError;
NSDictionary *responseResult = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
if (!jsonError) {
// 网络请求成功处理
// NSLog(@"%@", [responseResult objectForKey:@"error_code"]);
NSLog(@"%@", responseResult);
} else {
// 解析结果异常处理
NSLog(@"解析结果异常");
}
}
}];
[task resume];
返回参数说明:
| 名称 | 类型 | 说明 | |
|---|---|---|---|
| error_code | int | 返回状态码 | |
| reason | string | 返回原因 | |
| result | object | 结果对象 | |
| id | string | 新闻唯一ID,如:9a876fae9e98e9a07ed9c457e8504d1f | |
| title | string | 新闻标题,如:大雾橙色预警!湖北多地现能见度小于200米的雾 | |
| picUrl | string | 新闻配图,如:http://n.sinaimg.cn/hb/87/w574h313/20191202/00f9-ikcacer4044078.jpg | |
| description | string | 新闻描述 | |
| source | string | 新闻来源,如:湖北天气 | |
| url | string | 新闻链接,如:http://hb.sina.com.cn/news/j/2019-12-02/detail-iihnzhfz3050537.shtml | |
| ctime | string | 时间,如:2019-12-02 10:51:00 | |
JSON返回示例:JSON在线格式化工具 >
{
"reason": "success",
"result": {
"list": [
{
"id": "03c0df5c79adc94ec3c00a8134f06d44",
"ctime": "2022-11-28 00:01:00",
"title": "河海大学举行纪念严恺院士诞辰110周年座谈会",
"description": "",
"picUrl": "",
"url": "http://news.jschina.com.cn/focus/202211/t20221128_3119769.shtml",
"source": "中国江苏网"
},
{
"id": "247b536ea75e0e69114533ebb9c3ef2d",
"ctime": "2022-11-27 23:50:00",
"title": "河海大学举办新时期水利高等教育高质量发展大会",
"description": "",
"picUrl": "",
"url": "http://news.jschina.com.cn/focus/202211/t20221127_3119768.shtml",
"source": "中国江苏网"
},
{
"id": "98f24d29d7a3db32a52422744a7ce92b",
"ctime": "2022-11-25 20:32:00",
"title": "南京理工大学成立“青雁讲师团”",
"description": "",
"picUrl": "",
"url": "http://news.jschina.com.cn/focus/202211/t20221125_3119007.shtml",
"source": "中国江苏网"
},
{
"id": "d686ab0641a5611b1dd10ebf060e1e40",
"ctime": "2022-11-19 23:12:00",
"title": "“书”式“长跑”,2022长三角阅读马拉松大赛南京图书馆赛区完赛",
"description": "",
"picUrl": "",
"url": "http://news.jschina.com.cn/focus/202211/t20221119_3114863.shtml",
"source": "中国江苏网"
},
{
"id": "7e115e9e2171947b5971cee6ed369177",
"ctime": "2022-10-31 09:29:00",
"title": "“万古之梅”再度入宁,三位院士在南京中山植物园共植银缕梅",
"description": "",
"picUrl": "",
"url": "http://news.jschina.com.cn/focushttps://mjschina.com.cn/v3/waparticles/01166a4745744b46bdaf900b32795c42/0pLdzukGzdrhRd5B/1",
"source": "中国江苏网"
},
{
"id": "06a5d07696873d1ecc43c075f6346d04",
"ctime": "2022-09-21 20:46:00",
"title": "2025年底,江苏建成“智慧住房和城乡建设”平台",
"description": "",
"picUrl": "",
"url": "http://news.jschina.com.cn/focus/202209/t20220921_3080165.shtml",
"source": "中国江苏网"
},
{
"id": "6bef8d83fcd76e60300460404420507e",
"ctime": "2022-09-19 15:52:00",
"title": "河海大学党委书记唐洪武寄语新生:来一场青春与时代的“双向奔赴”",
"description": "",
"picUrl": "",
"url": "http://news.jschina.com.cn/focus/202209/t20220919_3078401.shtml",
"source": "中国江苏网"
},
{
"id": "39cf55a3eaadbbd23c5bf0a25f48b788",
"ctime": "2022-09-19 15:39:00",
"title": "河海大学举行2022年新生开学典礼",
"description": "",
"picUrl": "",
"url": "http://news.jschina.com.cn/focus/202209/t20220919_3078392.shtml",
"source": "中国江苏网"
},
{
"id": "bbe34d609402c5c1827554da68117f44",
"ctime": "2022-08-27 11:23:00",
"title": "主题集市、花式特调、音乐Party……“还有生活·cheers微醺季”点亮南京夜经济",
"description": "",
"picUrl": "",
"url": "http://news.jschina.com.cn/focus/202208/t20220827_3064140.shtml",
"source": "中国江苏网"
}
]
},
"error_code": 0
}
服务级错误码参照(error_code):
| 错误码 | 说明 | |
|---|---|---|
| 273100 | 网络超时,请稍后重试 | |
| 273101 | 地区名不能为空并且超过100字 | |
| 273102 | 数据异常 | |
| 273103 | 其他错误,具体看描述 |
系统级错误码参照:
| 错误码 | 说明 | 旧版本(resultcode) | |
|---|---|---|---|
| 10001 | 错误的请求KEY | 101 | |
| 10002 | 该KEY无请求权限 | 102 | |
| 10003 | KEY过期 | 103 | |
| 10004 | 错误的OPENID | 104 | |
| 10005 | 应用未审核超时,请提交认证 | 105 | |
| 10007 | 未知的请求源 | 107 | |
| 10008 | 被禁止的IP | 108 | |
| 10009 | 被禁止的KEY | 109 | |
| 10011 | 当前IP请求超过限制 | 111 | |
| 10012 | 请求超过次数限制 | 112 | |
| 10013 | 测试KEY超过请求限制 | 113 | |
| 10014 | 系统内部异常(调用充值类业务时,请务必联系客服或通过订单查询接口检测订单,避免造成损失) | 114 | |
| 10020 | 接口维护 | 120 | |
| 10021 | 接口停用 | 121 |
错误码格式说明(示例:200201):
| 2 | 002 | 01 | |
|---|---|---|---|
| 服务级错误(1为系统级错误) | 服务模块代码(即数据ID) | 具体错误代码 |
接口文档下载
苏公网安备 32059002001776号