如何使用百度云API介面

如何使用百度云API介面,第1张

如何使用百度云API介面 :developer.baidu./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介面的使用;初步是想做一个线上android应用,应用中的文件是存放在百度云盘的。

主要是分一下几个步骤:

1.注册百度账号

2.登入百度开发者中心

3.建立移动应用,获取对应的(API Key Secret Key)

4.开通pcs API许可权

5.获取ACCESS_token(认证编码)

6.开发应用

注意:

开通移动应用,获取key

获取token的时候我使用的安卓获取的方式

通过我写对应api的例子我发现,其实就两种情况:一种是get方式提交资料,另外一种是post方式提交资料

1.get方式提交资料,我们用获取云盘的资讯为例:

获取云盘资讯前我们要知道,我们要准备好什么资料:

请求引数:

url: 标明我们要访问的网址路径 值固定问""

method:标明我们是请求云盘资讯 值固定为"info"

aeess_token:准入标识 值是我们自己申请的

接收返回引数:

quota:云盘总容量

used:云盘使用容量

request_id:该请求的表示,没啥用

返回的一个json串如下格式:{"quota":123794882560, "used":83573494688,"request_id":2853739529}

我在做的时候你使用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(),"gb2312");

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=info&aess_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(),"gb2312");

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=info&aess_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":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 .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"

aeess_token:准入标识 值是我们自己申请的

path:是我们要上传到云盘的那个路径下 如/apps/myBaiduCloud/ myBaiduCloud是我们的应用名称(当你获取koten后就会自动生成以你应用名称为名的资料夹)

file:这个就是我们要上传的档案了(要求用post方式上传)

ondup:可选引数,标识当有重名的档案的时候处理方式具体见api

接收返回引数:

返回的也是json串,

path:为我们上传的档案储存的全路径

size:档案的大小有多少位元组

ctime/mtime:档案的建立修改时间

其他引数介绍点小标题去api中检视

{

"path" : "/apps/album/README.md"

"size" : 372121,

"ctime" : 1234567890,

"mtime" : 1234567890,

"md5" : "cb123af12453543ef",

"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=upload&aess_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 *** = new StringBuffer();

String line

while((line=buReader.readLine())!=null){

*** .append(line);

}

buReader.close();

解析成物件

Gson gson = new Gson();

FileBase cloudInfo = gson.fromJson( *** .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=upload&aess_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 *** = new StringBuffer();

String line

while((line=buReader.readLine())!=null){

*** .append(line);

}

buReader.close();

解析成物件

Gson gson = new Gson();

FileBase cloudInfo = gson.fromJson( *** .toString(), FileBase.class);

return cloudInfo

}

上面程式码成功后我们就会在/apps/mybaidu/目录下找到README.md档案

mons-codec-1.3.jar

mons-

mons-logging.jar

gson-2.2.1.jar

jsoup-1.6.3.jar

如何使用百度天气预报API介面

这个天气预报介面可以呢::sojson./blog/234.

天气API JSON返回方式

我测试一下请求北京的天气,连结为::sojson./open/api/weather/json.s?city=北京

天气API JSON返回方式(成功)

{"status": 200,"data": {"wendu": "29","ganmao": "各项气象条件适宜,发生感冒机率较低。但请避免长期处于空调房间中,以防感冒。","forecast": [{"fengxiang": "南风","fengli": "3-4级","high": "高温 32℃","type": "多云","low": "低温 17℃","date": "16日星期二"},{"fengxiang": "南风","fengli": "微风级","high": "高温 34℃","type": "晴","low": "低温 19℃","date": "17日星期三"},{"fengxiang": "南风","fengli": "微风级","high": "高温 35℃","type": "晴","low": "低温 22℃","date": "18日星期四"},{"fengxiang": "南风","fengli": "微风级","high": "高温 35℃","type": "多云","low": "低温 22℃","date": "19日星期五"},{"fengxiang": "南风","fengli": "3-4级","high": "高温 34℃","type": "晴","low": "低温 21℃","date": "20日星期六"}],"yesterday": {"fl": "微风","fx": "南风","high": "高温 28℃","type": "晴","low": "低温 15℃","date": "15日星期一"},"aqi": "72","city": "北京"},"message": "OK"}

如何使用百度云

你好, 百度云提供的是个人云储存服务,您可以把自己的资源、档案上传到云端,永久储存,省去硬碟、u盘,

并且可以在云端进行一系列 *** 作,比如:免费分享档案给小伙伴,线上看电影,离线下载等等。

百度云在各个终端(iPhone、Android、MAC、iPad)都有客户端,可同步使用,非常便利。

而且在手机上安装百度云客户端后,可以备份照片、通讯录、通话记录、简讯,给宝贵的资料多了一层保护,Android手机客户端还有手机找回功能。

祝您生活愉快!

希望我的回答对您有所帮助,能得到您的采纳!

如何使用百度云盘

手机需要用百度云管家软体,电影可以用百度云管家或网页版。

需要下载百度云客户端,登入百度账号。然后你就可以上传或者下载了。

如何使用google地图api介面

没用vpn或在国外是使用不了的,

因为被中国给限制了,

即使帮你申请了最近或平时也是经常使用不了的,

而且帮你注册的人家随时可以修改密码,不安全,没保障。

如果真的要用,方法和步骤:

1、51vpn支援国外就可以了。

2、vpn连线之后就可以开启谷歌和注册及使用了哦。

如何使用百度api store

当你克服重重困难终于开发出了自己的app,下一步就是向app store提交应用了,这时应该如何 *** 作呢?我的app真的准备好提交了?我敢肯定这些问题将会浮现在你的脑海。基于这篇教程,我将告诉你一个完整的提交过程。

搜寻引擎中搜索百度 api store,找到百度 api store的官网,进入官网

开启官网后,首页展示各种api服务及常用的api服务

点选导航栏中的api服务或者首页检视全部,进入api分类列表页面

以资料服务-->生活常用为例。进入相关生活常用的api服务列表

选择我们常用的IP地址查询的api,

点选进入IP地址查询页面,点选页面中的api页签

进入api页面,找到去除错 连结

输入你需查询的ip,就可以查询出ip的详细资讯

调整导航方向:

1、打开,设置好目的地,点击导航按钮,开始导航;

2、在导航界面,点击右下角三横线,出现设置界面;

3、在“导航视角”下,点击“车头向上”或者“正北朝上”即可。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/tougao/12000943.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存