本篇文章给大家谈谈调用百度api接口,以及调用百度api接口能下载多少数据对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
今天给各位分享调用百度api接口的知识,其中也会对调用百度api接口能下载多少数据进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
网页内如何调用开放的api接口实现用户定位
网页内调用开放的api接口实现用户定位的步骤如下:以百度地图为例
1、百度直接搜【百度地图调用】,点击出现的第二个网站,进入这个网站即可;
2、进入这个网站后,我们首先得输入自己需要定位的地点。比如我们输入【上海】这个城市,输入后点击【查找】选项;
3、经过上一步的操作,我们已经成功地定位到【上海】这个城市了。然后我们点击第二步【设置地图】;
4、在【设置地图】里面有一些关于这个地图本身显示的一些设置选项,比如可以设置地图的【尺寸大小】,地图的【添加按钮】和地图的【状态】;;
5、然后我们开始给我们的地图添加【地图标注】,点击这个【小棒子】图标,然后在我们需要标注的地方鼠点击一下,输入需要修改的名称和备注,然后点击【保存】按钮;
6、经过上面的一些操作后,我们可以看到我们自己添加的地理位置所显示出的效果了;
7、然后我们点击底部的【获取代码】,再点击【复制代码】即可;
8、在vs2012里面新建一个【html】文件,然后把我们刚刚复制过来的代码直接粘贴到里面。然后在vs2012里面选择使用【谷歌浏览器】查看这个【html】文件里面的内容;;
9、这个是在【谷歌浏览器】里面运行出来的,在本地的百度地图显示出地理位置的效果图。可以看到,我们已经成功地调用了百度地图的API接口了。

Baidu云盘API接口的使用使用说明
这几天很有兴致的学习了百度云盘文件API接口的使用 初步是想做一个在线android应用 应用中的文档是存放在百度云盘的 主要是分一下几个步骤 注册百度账号 登录百度开发者中心 创建移动应用 获取对应的(API Key Secret Key) 开通pcs API权限 获取ACCESS_token(认证编码) 开发应用 注意 开通移动应用 获取key 获取token的时候我使用的安卓获取的方式 通过我写对应api的例子我发现 其实就两种情况 一种是get方式提交数据 另外一种是post方式提交数据 get方式提交数据 我们用获取云盘的信息为例 获取云盘信息前我们要知道 我们要准备好什么数据 请求参数 url: 标明我们要访问的网址路径 值固定问 method:标明我们是请求云盘信息 值固定为 info acceess_token:准入标识 值是我们自己申请的 接收返回参数 quota:云盘总容量 used:云盘使用容量 request_id:该请求的表示 没啥用 返回的一个json串如下格式 { quota : used : request_id : } 我在做的时候你使用Gson工具将json串转换到对应的entity类中了 代码如下 [] /** * @param URLConnection conn通过get方式获取StringBuffer * @return */ private StringBuffer getJsonString(URLConnection conn) { InputStreamReader isr = null; BufferedReader br = null; StringBuffer *** = null; try { isr = new InputStreamReader(conn getInputStream() gb ) br = new BufferedReader(isr) String line = null; *** = new StringBuffer() while ((line = br readLine()) != null) { *** append(line) *** append( \r\n ) } } catch (UnsupportedEncodingException e) { e printStackTrace() } catch (IOException e) { e printStackTrace() }finally{ try { if(isr!=null) isr close() } catch (IOException e) { System out println( 流关闭是异常 ) e printStackTrace() } } return *** ; } /** * @return * @throws Exception * 获取云空间的信息 */ public CloudInfo getCloudInfo() throws Exception { URL u = new URL( ?method=infoaccess_token=你申请的token的值 ; URLConnection conn = u openConnection() // 打开网页链接 // 获取用户云盘信息 String cloudJson = this getJsonString(conn) toString()
// 解析成对象 下面有这个实体对象的类 Gson gson = new Gson() CloudInfo cloudInfo = gson fromJson(cloudJson CloudInfo class) System out println( 云盘信息 +cloudInfo) return cloudInfo; } /** * @param URLConnection conn通过get方式获取StringBuffer * @return */ private StringBuffer getJsonString(URLConnection conn) { InputStreamReader isr = null; BufferedReader br = null; StringBuffer *** = null; try { isr = new InputStreamReader(conn getInputStream() gb ) br = new BufferedReader(isr) String line = null; *** = new StringBuffer() while ((line = br readLine()) != null) { *** append(line) *** append( \r\n ) } } catch (UnsupportedEncodingException e) { e printStackTrace() } catch (IOException e) { e printStackTrace() }finally{ try { if(isr!=null) isr close() } catch (IOException e) { System out println( 流关闭是异常 ) e printStackTrace() } } return *** ; } /** * @return * @throws Exception * 获取云空间的信息 */ public CloudInfo getCloudInfo() throws Exception { URL u = new URL( ?method=infoaccess_token=你申请的token的值 ; URLConnection conn = u openConnection() // 打开网页链接 // 获取用户云盘信息 String cloudJson = this getJsonString(conn) toString() // 解析成对象 下面有这个实体对象的类 Gson gson = new Gson() CloudInfo cloudInfo = gson fromJson(cloudJson CloudInfo class) System out println( 云盘信息 +cloudInfo) return cloudInfo; } [] package entity; import java lang reflect Type; /** * @author ydcun 获取云空间的信息 例如 * { quota : 空间配额 单位为字节 * used : 已使用空间大小 单位为字节 * request_id : } */ public class CloudInfo{ private Double quota; private Double used; private Double request_id; /** * @return the quota 空间配额 单位为字节 */ public Double getQuota() { return quota; } /** * @param quota the quota to set 空间配额 单位为字节 */ public void setQuota(Double quota) { this quota = quota; } /** * @return the used 已使用空间大小 单位为字节 */ public Double getused() { return used; } /** * @param used the used to set 已使用空间大小 单位为字节 */ public void setused(Double used) { this used = used; } /** * @return the request_id */ public Double getRequest_id() { return request_id; } /** * @param request_id the request_id to set */ public void setRequest_id(Double request_id) { this request_id = request_id; } @Override public String toString() { return new StringBuffer() append( 空间容量 ) append(this getQuota()/ / ) append( M; 已用 ) append(this getused()/ / ) append( M; ) toString() } } package entity; import java lang reflect Type; /** * @author ydcun 获取云空间的信息 例如 * { quota : 空间配额 单位为字节 * used : 已使用空间大小 单位为字节 * request_id : } */ public class CloudInfo{ private Double quota; private Double used; private Double request_id; /** * @return the quota 空间配额 单位为字节 */ public Double getQuota() { return quota; } /** * @param quota the quota to set 空间配额 单位为字节 */ public void setQuota(Double quota) { this quota = quota; } /** * @return the used 已使用空间大小 单位为字节 */ public Double getused() { return used; } /** * @param used the used to set 已使用空间大小 单位为字节 */ public void setused(Double used) { this used = used; } /** * @return the request_id */ public Double getRequest_id() { return request_id; } /** * @param request_id the request_id to set */ public void setRequest_id(Double request_id) { this request_id = request_id; } @Override public String toString() { return new StringBuffer() append( 空间容量 ) append(this getQuota()/ / ) append( M; 已用 ) append(this getused()/ / ) append( M; ) toString() } }
lishixinzhi/Article/program/Java/hx/201311/27162
如何调用百度地图API
百度地图API
开始学习百度地图API最简单的方式是看一个简单的示例。以下代码创建了一个520x340大小的地图区域并以天安门作为地图的中心:
1. <html
2. <head
3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
4. <titleHello, World</title
5. <script type="text/javascript" src="http://api.map.baidu.com/api?key=46ce9d0614bf7aefe0ba562f8cf87194v=1.0services=false"</script
6. </head
7. <body
8. <div style="width:520px;height:340px;border:1px solid gray" id="container"</div
9. </body
10. </html
11.
12.
<html
<head
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
<titleHello, World</title
<script type="text/javascript" src="http://api.map.baidu.com/api?key=46ce9d0614bf7aefe0ba562f8cf87194v=1.0services=false"</script
</head
<body
<div style="width:520px;height:340px;border:1px solid gray" id="container"</div
</body
</html
1. <script type="text/javascript"
2. var map = new BMap.Map("container"); // 创建地图实例
3. var point = new BMap.Point(116.404, 39.915); // 创建点坐标
4. map.centerAndZoom(point, 15); // 初始化地图,设置中心点坐标和地图级别
5. </script
6.
<script type="text/javascript"
var map = new BMap.Map("container"); // 创建地图实例
var point = new BMap.Point(116.404, 39.915); // 创建点坐标
map.centerAndZoom(point, 15); // 初始化地图,设置中心点坐标和地图级别
</script
引用百度地图API文件
当您引用地图API文件时,需要使用自己申请的API密钥。
1. <script type="text/javascript" src="http://api.map.baidu.com/api?key=46ce9d0614bf7aefe0ba562f8cf87194v=1.0services=false"</script
<script type="text/javascript" src="http://api.map.baidu.com/api?key=46ce9d0614bf7aefe0ba562f8cf87194v=1.0services=false"</script
创建地图容器元素
1. <div style="width:520px;height:340px;border:1px solid #000" id="container"</div
<div style="width:520px;height:340px;border:1px solid #000" i
如何使用百度云API接口
http://developer.baidu.com/wiki/index.php?title=%E5%B8%AE%E5%8A%A9%E6%96%87%E6%A1%A3%E9%A6%96%E9%A1%B5/%E8%B5%84%E6%BA%90%E4%B8%8B%E8%BD%BD
学习了百度云盘文件API接口的使用
调用百度api接口;初步是想做一个在线android应用
调用百度api接口,应用中的文档是存放在百度云盘的。
主要是分一下几个步骤:
1.注册百度账号
2.登录百度开发者中心
3.创建移动应用,获取对应的(API Key Secret Key)
4.开通pcs API权限
5.获取ACCESS_token(认证编码)
6.开发应用
注意:
开通移动应用,获取key
获取token的时候我使用的安卓获取的方式
通过我写对应api的例子我发现,其实就两种情况:一种是get方式提交数据,另外一种是post方式提交数据
1.get方式提交数据,我们用获取云盘的信息为例:
获取云盘信息前我们要知道,我们要准备好什么数据:
请求参数:
url: 标明我们要访问的网址路径 值固定问""
method:标明我们是请求云盘信息 值固定为"info"
acceess_token:准入标识 值是我们自己申请的
接收返回参数:
quota:云盘总容量
used:云盘使用容量
request_id:该请求的表示,没啥用
返回的一个json串如下格式:{"quota":123794882560, "used":83573494688,"request_id":2853739529}
我在做的时候你使用Gson工具将json串转换到对应的entity类中了 代码如下:
[html] /**
* @param URLConnection conn通过get方式获取StringBuffer
* @return
*/
private StringBuffer getJsonString(URLConnection conn) {
InputStreamReader isr = null;
BufferedReader br = null;
StringBuffer sb = null;
try {
isr = new InputStreamReader(conn.getInputStream(),"gb2312");
br = new BufferedReader(isr);
String line = null;
sb = new StringBuffer();
while ((line = br.readLine()) != null) {
sb.append(line);
sb.append("\r\n");
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
if(isr!=null)
isr.close();
} catch (IOException e) {
System.out.println("流关闭是异常");
e.printStackTrace();
}
}
return sb;
}
/**
* @return
* @throws Exception
* 获取云空间的信息
*/
public CloudInfo getCloudInfo() throws Exception {
URL u = new URL("?method=infoaccess_token=你申请的token的值";
URLConnection conn = u.openConnection();// 打开网页链接
// 获取用户云盘信息
String cloudJson = this.getJsonString(conn)。toString();
// 解析成对象 下面有这个实体对象的类
Gson gson = new Gson();
CloudInfo cloudInfo = gson.fromJson(cloudJson, CloudInfo.class);
System.out.println("云盘信息:"+cloudInfo);
return cloudInfo;
}
/**
* @param URLConnection conn通过get方式获取StringBuffer
* @return
*/
private StringBuffer getJsonString(URLConnection conn) {
InputStreamReader isr = null;
BufferedReader br = null;
StringBuffer sb = null;
try {
isr = new InputStreamReader(conn.getInputStream(),"gb2312");
br = new BufferedReader(isr);
String line = null;
sb = new StringBuffer();
while ((line = br.readLine()) != null) {
sb.append(line);
sb.append("\r\n");
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
if(isr!=null)
isr.close();
} catch (IOException e) {
System.out.println("流关闭是异常");
e.printStackTrace();
}
}
return sb;
}
/**
* @return
* @throws Exception
* 获取云空间的信息
*/
public CloudInfo getCloudInfo() throws Exception {
URL u = new URL("?method=infoaccess_token=你申请的token的值";
URLConnection conn = u.openConnection();// 打开网页链接
// 获取用户云盘信息
String cloudJson = this.getJsonString(conn)。toString();
// 解析成对象 下面有这个实体对象的类
Gson gson = new Gson();
CloudInfo cloudInfo = gson.fromJson(cloudJson, CloudInfo.class);
System.out.println("云盘信息:"+cloudInfo);
return cloudInfo;
}
[html] package com.entity;
import java.lang.reflect.Type;
/**
* @author ydcun 获取云空间的信息 例如:
* {"quota":123794882560, 空间配额,单位为字节
* "used":83573494688, 已使用空间大小 单位为字节。
* "request_id":2853739529}
*/
public class CloudInfo{
private Double quota;
private Double used;
private Double request_id;
/**
* @return the quota 空间配额,单位为字节
*/
public Double getQuota() {
return quota;
}
/**
* @param quota the quota to set 空间配额,单位为字节
*/
public void setQuota(Double quota) {
this.quota = quota;
}
/**
* @return the used 已使用空间大小 单位为字节
*/
public Double getused() {
return used;
}
/**
* @param used the used to set 已使用空间大小 单位为字节
*/
public void setused(Double used) {
this.used = used;
}
/**
* @return the request_id
*/
public Double getRequest_id() {
return request_id;
}
/**
* @param request_id the request_id to set
*/
public void setRequest_id(Double request_id) {
this.request_id = request_id;
}
@Override
public String toString() {
return new StringBuffer()。append("空间容量:")。append(this.getQuota()/1024/1024)。append("M; 已用:")。append(this.getused()/1024/1024)。append("M; ")。toString();
}
}
package com.entity;
import java.lang.reflect.Type;
/**
* @author ydcun 获取云空间的信息 例如:
* {"quota":123794882560, 空间配额,单位为字节
* "used":83573494688, 已使用空间大小 单位为字节。
* "request_id":2853739529}
*/
public class CloudInfo{
private Double quota;
private Double used;
private Double request_id;
/**
* @return the quota 空间配额,单位为字节
*/
public Double getQuota() {
return quota;
}
/**
* @param quota the quota to set 空间配额,单位为字节
*/
public void setQuota(Double quota) {
this.quota = quota;
}
/**
* @return the used 已使用空间大小 单位为字节
*/
public Double getused() {
return used;
}
/**
* @param used the used to set 已使用空间大小 单位为字节
*/
public void setused(Double used) {
this.used = used;
}
/**
* @return the request_id
*/
public Double getRequest_id() {
return request_id;
}
/**
* @param request_id the request_id to set
*/
public void setRequest_id(Double request_id) {
this.request_id = request_id;
}
@Override
public String toString() {
return new StringBuffer()。append("空间容量:")。append(this.getQuota()/1024/1024)。append("M; 已用:")。append(this.getused()/1024/1024)。append("M; ")。toString();
}
}
2.通过post方式提交 我用上传单个文件为例子:
同样我们也先了解下上传文件要参数设置:
请求参数:
url: 标明我们要访问的网址路径 值固定问""
method:标明我们是请求云盘信息 值固定为"upload"
acceess_token:准入标识 值是我们自己申请的
path:是我们要上传到云盘的那个路径下 如/apps/myBaiduCloud/ myBaiduCloud是我们的应用名称(当你获取koten后就会自动生成以你应用名称为名的文件夹)
file:这个就是我们要上传的文件了(要求用post方式上传)
ondup:可选参数,标识当有重名的文件的时候处理方式具体见api
接收返回参数:
返回的也是json串,
path:为我们上传的文件保存的全路径
size:文件的大小有多少字节
ctime/mtime:文件的创建修改时间
其
调用百度api接口他参数介绍点小标题去api中查看
{
"path" : "/apps/album/README.md"
"size" : 372121,
"ctime" : 1234567890,
"mtime" : 1234567890,
"md5" : "cb123afcc12453543ef",
"fs_id" : 12345,
"request_id":4043312669
}
我在做的时候也是将其封装到实体类中了,这里和上面一样不详述,我们重点看下提交文件是怎么提交的代码如下:
[java] /**
* @param path 云盘存放路径
* @param name 要上传的文件
* @return
* @throws Exception
*/
public FileBase uploadFile(String path,File file) throws Exception{
//模拟文件
String fileName="README.md";
file = new File(fileName);
path="%2fapps%2fmybaidu%2f"; // 我用的是url编码过源码为:- "/apps/mybaidu/
/"
//将需要url传值的参数和url组装起来
String u =""+path+file.getName()+"method=uploadaccess_token=你自己申请的token值";
PostMethod filePost = new PostMethod(u);
//post提交的参数
Part[] parts = {new FilePart(fileName,file)};
//设置多媒体参数,作用类似form表单中的enctype="multipart/form-data"
filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
HttpClient clients = new HttpClient();
//响应代码
int status = clients.executeMethod(filePost);
System.out.println("成功上传"+path+fileName);
BufferedReader buReader = new BufferedReader(new InputStreamReader(filePost.getResponseBodyAsStream(),"utf-8"));
StringBuffer sb = new StringBuffer();
String line;
while((line=buReader.readLine())
调用百度api接口!=null){
sb.append(line);
}
buReader.close();
// 解析成对象
Gson gson = new Gson();
FileBase cloudInfo = gson.fromJson(sb.toString(), FileBase.class);
return cloudInfo;
}
/**
* @param path 云盘存放路径
* @param name 要上传的文件
* @return
* @throws Exception
*/
public FileBase uploadFile(String path,File file) throws Exception{
//模拟文件
String fileName="README.md";
file = new File(fileName);
path="%2fapps%2fmybaidu%2f"; // 我用的是url编码过源码为:- "/apps/mybaidu/
/"
//将需要url传值的参数和url组装起来
String u =""+path+file.getName()+"method=uploadaccess_token=你自己申请的token值";
PostMethod filePost = new PostMethod(u);
//post提交的参数
Part[] parts = {new FilePart(fileName,file)};
//设置多媒体参数,作用类似form表单中的enctype="multipart/form-data"
filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams()));
HttpClient clients = new HttpClient();
//响应代码
int status = clients.executeMethod(filePost);
System.out.println("成功上传"+path+fileName);
BufferedReader buReader = new BufferedReader(new InputStreamReader(filePost.getResponseBodyAsStream(),"utf-8"));
StringBuffer sb = new StringBuffer();
String line;
while((line=buReader.readLine())!=null){
sb.append(line);
}
buReader.close();
// 解析成对象
Gson gson = new Gson();
FileBase cloudInfo = gson.fromJson(sb.toString(), FileBase.class);
return cloudInfo;
}
上面代码成功后我们就会在/apps/mybaidu/目录下找到README.md文件
commons-codec-1.3.jar
commons-
commons-logging.jar
gson-2.2.1.jar
jsoup-1.6.3.jar
如何使用百度天气预报API接口
百度API Key申请地址:http://lbsyun.baidu.com/apiconsole/key
创建应用 如图:
提交后得到API Key ,运行结果如下:
扩展资料:
API(Application Programming Interface,应用程序编程接口)是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件得以访问一组例程的能力,而又无需访问源码,或理解内部工作机制的细节。
API函数包含在Windows系统目录下的动态连接库文件中。Windows API是一套用来控制Windows的各个部件的外观和行为的预先定义的Windows函数。
参考资料:百度百科-api接口
关于调用百度api接口和调用百度api接口能下载多少数据的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
调用百度api接口的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于调用百度api接口能下载多少数据、调用百度api接口的信息别忘了在本站进行查找喔。
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~