예제 #1
0
 function testMetadataList()
 {
     //实例化 \Vdisk\OAuth2
     $oauth2 = new \Vdisk\OAuth2(VDISK_CLIENT_ID, VDISK_CLIENT_SECRET);
     $token = $oauth2->getTokenFromObject($_SESSION['token']);
     $client = new \Vdisk\Client($oauth2, 'basic');
     //$client->setDebug(true);
     $path = '/';
     // Attempt to retrieve the account information
     $response = $client->metaData($path);
     $metaData = $response['body'];
     /*
     [size] => 0 bytes
     [rev] => 1bd26196
     [thumb_exists] => 
     [bytes] => 0
     [modified] => Fri, 15 Mar 2013 03:06:35 +0000
     [path] => /
     [is_dir] => 1
     [root] => basic
     [icon] => folder
     [revision] => 0
     [is_deleted] =>
     [hash] => c6bb111aa75c2cc619fca7e77b1a1f5a
     */
     $this->assertIsA($metaData, 'stdClass');
     $this->assertTrue($metaData->is_dir);
     $this->assertTrue(isset($metaData->rev));
     $this->assertTrue(isset($metaData->thumb_exists));
     $this->assertEqual($metaData->size, '0 bytes');
     $this->assertEqual($metaData->root, 'basic');
     $this->assertEqual($metaData->icon, 'folder');
     $this->assertTrue(isset($metaData->is_deleted));
     $this->assertPattern("/^[0-9a-f]{32}\$/", $metaData->hash);
     $this->assertIsA($metaData->contents, 'array');
 }
예제 #2
0
 * PHP SDK for Sina Vdisk (using OAuth2)
 * @author Bruce Chen <*****@*****.**>
 */
/*
phpdoc run -f ./Vdisk/Vdisk.php -t ./Doc --sourcecode --title "新浪微盘SDK For PHP" --hidden --validate
*/
include_once 'config.php';
session_start();
if (isset($_GET['logout']) && $_GET['logout'] == 1) {
    //退出登录, 清除SESSION
    session_destroy();
    header('Location: index.php');
}
$is_login = false;
//实例化 \Vdisk\OAuth2
$oauth2 = new \Vdisk\OAuth2(VDISK_CLIENT_ID, VDISK_CLIENT_SECRET);
//判断是否登录, 并且给$oauth2->accessToken负值
if (isset($_SESSION['token']) && isset($_SESSION['token']->access_token) && ($token = $oauth2->getTokenFromObject($_SESSION['token']))) {
    $is_login = true;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta http-equiv="Content-Style-Type" content="text/css">
  <title>新浪微盘SDK实例</title>
  <meta name="Generator" content="Cocoa HTML Writer">
  <meta name="CocoaVersion" content="1187.34">
  <style type="text/css"></style>
예제 #3
0
<?php

include_once 'config.php';
session_start();
//实例化 \Vdisk\OAuth2
$oauth2 = new \Vdisk\OAuth2(VDISK_CLIENT_ID, VDISK_CLIENT_SECRET);
//判断是否登录, 并且给$oauth2->accessToken负值
if (isset($_SESSION['token']) && isset($_SESSION['token']->access_token) && ($token = $oauth2->getTokenFromObject($_SESSION['token']))) {
    $client = new \Vdisk\Client($oauth2, 'basic');
    $client->setDebug(true);
    try {
        // Attempt to retrieve the account information
        $response = $client->accountInfo();
        $accountInfo = $response['body'];
        // Dump the output
        echo "<pre>";
        print_r($accountInfo);
        echo "</pre>";
    } catch (\Vdisk\Exception $e) {
        echo "<pre>";
        echo get_class($e) . ' ' . '#' . $e->getCode() . ': ' . $e->getMessage();
        echo "</pre>";
    }
} else {
    echo "您还没有登录, <a href='index.php'>去登录</a>";
}
예제 #4
0
<?php

/**
 * PHP SDK for Sina Vdisk (using OAuth2)
 * @author Bruce Chen <*****@*****.**>
 */
header('Content-Type: text/html; charset=UTF-8');
include_once 'config.php';
session_start();
$oauth2 = new \Vdisk\OAuth2(VDISK_CLIENT_ID, VDISK_CLIENT_SECRET);
$oauth2->debug = false;
if (isset($_REQUEST['code'])) {
    $keys = array();
    $keys['code'] = $_REQUEST['code'];
    $keys['redirect_uri'] = VDISK_CALLBACK_URL;
    try {
        $token = $oauth2->getAccessToken('code', $keys);
        $_SESSION['token'] = $token;
        header('Location: index.php');
    } catch (Exception $e) {
        echo "<pre>";
        print_r($e->getMessage());
        echo "</pre>";
        echo "<a href='index.php'>返回</a>";
    }
}
/*
if ($token) {
	
	$_SESSION['token'] = $token;
	
예제 #5
0
<?php

include_once 'Vdisk.php';
include_once 'config.php';
$oauth2 = new \Vdisk\OAuth2(VDISK_CLIENT_ID, VDISK_CLIENT_SECRET);
$tokenObj = loadToken();
if ($tokenObj != NULL and isset($tokenObj->access_token) and $oauth2->getTokenFromObject($tokenObj)) {
    $vdiskLogedIn = TRUE;
    $client = new \Vdisk\Client($oauth2, VDISK_AUTH_RIGHTS);
} else {
    $vdiskLogedIn = FALSE;
}