当前位置:首页 > 代码 > 正文

百度云存储api插件代码实例(百度网盘api开发文档)

admin 发布:2022-12-19 16:28 160


本篇文章给大家谈谈百度云存储api插件代码实例,以及百度网盘api开发文档对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

C#调用百度云API实现上传下载,要例子。谢谢

上传: private string Upload(HttpPostedFile pf,string ExtName) { FtpSupport.FtpConnection ftp=new FtpSupport.FtpConnection(); System.IO.Stream fs=pf.InputStream; string FileName=DateTime.Now.ToString( "yyyyMMddhhmmss "); FileName+= ". "+ExtName; (ConfigurationSettings.AppSettings[ "FtpIP "].ToString(),ConfigurationSettings.AppSettings[ "FtpUserName "].ToString(),ConfigurationSettings.AppSettings[ "FtpPassWord "].ToString()); ( "/ "); ; fs.Close(); ; return FileName; } 当下载的时候: private void FtpDown(string filename) { FtpSupport.FtpConnection ftp=new FtpSupport.FtpConnection();; try { (ConfigurationSettings.AppSettings[ "FtpIP "].ToString(),ConfigurationSettings.AppSettings[ "FtpUserName "].ToString(),ConfigurationSettings.AppSettings[ "FtpPassWord "].ToString()); try { ( "/ "); if(;filename!= " ") { Response.Write( " script window.open( 'ftp:// "+Server.UrlEncode(ConfigurationSettings.AppSettings[ "FtpUserName "].ToString())+ ": "+ConfigurationSettings.AppSettings[ "FtpPassWord "].ToString()+ "@ "+ConfigurationSettings.AppSettings[ "FtpIP "].ToString()+ "/ "+filename+ " ') /script "); } else { ClsOper.Alert( "Can Not Find File "); } } catch { ClsOper.Alert( "Can Not Operate FTP "); } finally { ; } } catch { ClsOper.Alert( "Can Not Connect FTP "); } }

如何使用百度云API接口

学习了百度云盘文件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"

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中查看

{

"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())!=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

百度云推送服务端SDK怎么用

使用方法如下:

1、先成为这个服务端的开发者,然后建一个立应用;

2、创建好应用之后,点击打开开发者服务管理,进入工程管理页面,然后点击左侧云推送,进入云推送功能页面;

3、进入云推送详细页面之后,在点击推送设置,设置好应用的包名,然后点击快速实例,将系统产生的示例代码下载下来进行了;

4、将下载好的代码导入Eclipse,开始准备整合;

5、经过整合之后,就得到的Demo代码;

6、这样,后台发送推送信息的时候,客户端就可以自动收到来自后台的推送了。

但是相比较来说,深圳极光会要好一点。创立于2011年,其团队核心成员来自腾讯、摩根士丹利、豆瓣、Teradata和中国移动等公司。2012年,公司旗下核心产品极光推送(JPush)正式问世,这是国内首个为移动应用开发者提供专业、高效的消息推送服务的产品。

谁会用C语言调用百度云API识别验证码

就是通过C语言发送HTTPS的POST请求。

百度一下示例代码就可以了。

做pc程序,如何获取百度云开放平台的API?

使用云存储服务,需要首先创建应用并获取应用密钥对。操作步骤如下:

1. 在管理中心创建一个应用

2. 在应用基本信息页,获取相应的“API key 及 Secret Key”

注:access_token不能泄露,否则会直接封禁应用。

创建Bucket,可通过以下三种方式来实现:

1. 通过云存储管理控制台创建bucket。可以把bucket看成是命名空间,您的数据就存储在这个bucket里面。

2. 通过调用 REST API接口 Put_Bucket实现

3. 通过SDK,调用相关接口来实现

使用云存储服务上传文件有以下四种途径:

1. 使用Shell Tool上传

2. 使用SDK进行上传

3. 直接使用curl命令上传

4. 通过云存储管理控制台上传

使用shell tool上传

了解使用shell tool上传文件的详细内容及下载shell tool,请参考Shell Tool相关介绍。

使用SDK上传

目前百度云存储服务已为广大开发者提供了以下SDK:

PHP SDK

Java SDK

Python SDK

C/C++(linux版本)SDK

如需下载相应的SDK,请点击这里。

直接使用curl上传

1. 获取上传链接:

上传地址:

bcs.duapp.com

获取上传链接:

通过云存储管理控制台的“URL签名”工具直接计算签名

填写以下信息:

Host: bcs.duapp.com

API Key: (“应用的基本信息页面”中查看)

Secret Key:

Method: PUT

Bucket: 在云存储管理平台中查看自己的bucket信息

Object:/testobject

点击“签名”按钮:签名后的地址已经全部列出来了,拷贝put操作对应的地址即可。

其实其他操作的签名也都算好了。

2. 上传文件:

例如:要上传本地文件bs.txt到云存储,并且命名为:testobject。

curl -T bs.txt -v

“"

直接通过管理控制台上传

通过云存储管理控制台,选择页面的“上传”即可。

没有bucket的情况下,需先创建bucket;

已创建bucket的情况下,选择并点击要上传文件的bucket名称,进入该bucket页面后再选择“上传文件”进行文件上传操作。

通过ACL设置bucket或object的访问权限。

创建bucket及上传文件时,默认是“私有”状态,通过ACL设置接口,可将其状态设置为公开或自定义访问权限。

设置为公开读(public-read)时,访问链接可不带签名,默认为所有人都可访问该资源。

设置为私有(private)时,访问链接需带签名,默认只有获取相关AKSK的用户才可访问该资源。

关于百度云存储api插件代码实例和百度网盘api开发文档的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/12999.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载