VdiskSDK-PHP

请先前往 微盘开发者中心 注册为微盘开发者, 并创建应用.

RESTful API文档: http://vdisk.weibo.com/developers/index.php?module=api&action=apidoc

Demo演示地址: http://vauth.appsina.com/

SDK For PHP文档地址: http://vauth.appsina.com/Doc/namespaces/Vdisk.html

关于微盘OPENAPI、SDK使用以及技术问题请联系: @一个开发者

QQ群: 134719337、162285095

邮箱: cloudside@sina.cn

Requirements

PHP >= 5.3.1 [PHP cURL]

Usage

用户授权

//实例化 VdiskOAuth2 $oauth2 = new VdiskOAuth2('您应用的appkey', '您应用的appsecret'); $auth_url = $oauth2->getAuthorizeURL('您在开发者中心设置的跳转地址'); /* 引导用户访问授权页面: $auth_url */ 获得access token

//用户授权成功后, 会跳转到你的callback地址, 您需要用code参数换取access token if (isset($_REQUEST['code'])) { $keys = array(); $keys['code'] = $_REQUEST['code']; $keys['redirect_uri'] = '您在开发者中心设置的跳转地址'; try { $token = $oauth2->getAccessToken('code', $keys); print_r(token); //得到access token } catch (Exception $e) { echo "<pre>"; print_r($e->getMessage()); echo "</pre>"; echo "<a href='index.php'>返回</a>"; } } 获得用户信息

$client = new VdiskClient($oauth2); $client->setDebug(true); //开启调试模式 try { // Attempt to retrieve the account information $response = $client->accountInfo(); //调用accountInfo方法 $accountInfo = $response['body']; // Dump the output echo "<pre>"; print_r($accountInfo); //打印用户信息 echo "</pre>"; } catch (VdiskException $e) { //捕获异常 echo "<pre>"; echo get_class($e) . ' ' . '#' . $e->getCode() . ': ' . $e->getMessage(); echo "</pre>"; } 获得文件列表、目录/文件信息

$client = new VdiskClient($oauth2, 'basic'); //$client->setDebug(true); //开启调试模式 try { if (isset($_GET['path'])) { $path = $_GET['path']; } else { $path = '/'; } // Attempt to retrieve the account information $response = $client->metaData($path); //调用metaData方法 $metaData = $response['body']; } catch (VdiskException $e) { //捕获异常 echo "<pre>"; echo get_class($e) . ' ' . '#' . $e->getCode() . ': ' . $e->getMessage(); echo "</pre>"; } 下载文件

$client = new VdiskClient($oauth2, 'basic'); $client->setDebug(true); //开启调试模式 try { $response = $client->getFile('云端文件的全路径', '下载到本地目标文件的全路径'); // Dump the output echo "<pre>"; print_r($response); echo "</pre>"; } catch (VdiskException $e) { //捕获异常 echo "<pre>"; echo get_class($e) . ' ' . '#' . $e->getCode() . ': ' . $e->getMessage(); echo "</pre>"; } 上传文件(POST)

$client = new VdiskClient($oauth2, 'basic'); $client->setDebug(true); //开启调试模式 try { $response = $client->putFile('本地文件真实路径', '要上传的目标全路径'); // Dump the output echo "<pre>"; print_r($response); echo "</pre>"; } catch (VdiskException $e) { //捕获异常 echo "<pre>"; echo get_class($e) . ' ' . '#' . $e->getCode() . ': ' . $e->getMessage(); echo "</pre>"; } 上传文件(PUT)

$client = new VdiskClient($oauth2, 'basic'); $client->setDebug(true); //开启调试模式 try { $response = $client->putStream(fopen('本地文件真实路径', 'r'), '云端目标文件全路径'); // Dump the output echo "<pre>"; print_r($response); echo "</pre>"; } catch (VdiskException $e) { //捕获异常 echo "<pre>"; echo get_class($e) . ' ' . '#' . $e->getCode() . ': ' . $e->getMessage(); echo "</pre>"; }

版权声明:

1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。
2、网站不提供资料下载,如需下载请到原作者页面进行下载。
3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考学习用!
4、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。