兼容Composer的Scribd PHP库(基于Robert Pottorff的版本

dev-master 2015-01-01 06:39 UTC

This package is not auto-updated.

Last update: 2024-09-23 11:27:36 UTC


README

这是一个与Composer兼容的Scribd客户端。您可以在Packagist上找到它:https://packagist.org.cn/packages/nikkobautista/scribd 这基于Robert Pottorff创建的原始版本。

安装

只需将包添加到您的composer.json文件的require属性中,如下所示

{
    "require": {
        "nikkobautista/scribd": "dev-master"
    },
}

使用方法

初始化

$scribd_api_key = "ENTER-YOUR-API-KEY-HERE";
$scribd_secret = "ENTER-YOUR-API-SECRET-HERE"; 
$scribd = new Scribd\API($scribd_api_key, $scribd_secret);

从文件上传文档

$file = '../testfile.txt'; //a reference to the file in reference to the current working directory.
$doc_type = null;
$access = null;
$rev_id = null;
$data = $scribd->upload($file, $doc_type, $access, $rev_id); // returns Array ( [doc_id] => 1026598 [access_key] => key-23nvikunhtextwmdjm2i )

从URL上传文档

$scribd->my_user_id = '143'; # The user ID of one of your users
$url = 'http://lib.store.yahoo.net/lib/paulgraham/onlisp.ps';
$doc_type = null;
$access = "public";
$rev_id = null; // By using a id stored in a database, you can update an existing document without creating a new one
$data = $scribd->uploadFromUrl($url, $doc_type, $access, $rev_id); // returns Array ( [doc_id] => 1021237 [access_key] => key-dogbmich9x5iu09kiki )

获取文档列表

$data = $scribd->getList();
/*
will return 
Array
(
    [result] => Array
    (
        [doc_id] => 1018558
        [access_key] => key-1s79um0eg9a355arn5sb
        [title] => dxva sig 68744
        [description] => 
        [conversion_status] => DONE
    ),
    ...
    ...
    ...
    [result 40] => Array
    (
        [doc_id] => 1021237
        [access_key] => key-dogbmich9x5iu09kiki
        [title] => onlisp
        [description] => 
        [conversion_status] => PROCESSING
    )
)
*/

获取文档转换状态

$doc_id = "1021237";
$data = $scribd->getConversionStatus($doc_id); // returns PROCESSING

获取文档设置(各种元信息)

$doc_id = "1026450";
$data = $scribd->getSettings($doc_id); // returns Array ( [doc_id] => 1021237 [title] => onlisp [description] => [access] => public [license] => by-nc [tags] => [show_ads] => default [access_key] => key-dogbmich9x5iu09kiki )

更改文档设置

$doc_ids = array("1026450"); // This dosen't HAVE to be an array, im simply demonstrating that it can be done with one.
$title = "New, Updated Title 2";
$description = "Updated Description";
$access = "private"; 
$license = "pd"; //public domain.. c for normal copyright.. ect.
$parental_advisory = "adult";
$show_ads = "false"; // setting this to "default" will use the configured option in your account
$tags = "tag, another tag, another tag"; //You can also use an array here
$data = $scribd->changeSettings($doc_ids, $title, $description, $access, $license, $parental_advisory, $show_ads, $tags); //returns 1

删除文档

$doc_id = "1024559";
$data = $scribd->delete($doc_id); //returns 1

以用户身份登录

$username = "aeinstein3";
$password = "whitehair";
$data = $scribd->login($username, $password); // Array ( [session_key] => sess-1d9t8wze460fbhp7jw0p [user_id] => 195134 [username] => aeinstein3 [name] => )

创建新的Scribd账户

注意:在添加文件之前,您需要以用户身份登录,注册并不会自动登录

$username = "aeinstein3";
$password = "whitehair";
$email = "ae04@gmail.com";
$name = "Alby Dinosour"; // optional
$data = $scribd->signup($username, $password, $email, $name); //returns Array ( [session_key] => sess-1d9t8wze460fbhp7jw0p [user_id] => 195134 [username] => aeinstein3 [name] => )

在Scribd上搜索文档

$query = "fun";
$num_results = 20;
$num_start = 10; // this will bring results 10-30 back
$scope = "all"; // user (default) or all -- using test will throw an error.

try{
    $data = $scribd->search($query, $num_results, $num_start, $scope); // returns
}catch( exception $e){
    $trace = $e->getTrace();
    echo "<br /><b>Scribd Error</b>: ".$e->getMessage()." in <b>".$trace[1]['file']."</b> on line <b>".$trace[1]['line']."</b><br />"; 
}

print_r($data);

/*

Assuming $scope is set to default or all :)

Array
(
    [result] => Array
        (
            [doc_id] => 501796
            [title] => Andrew Loomis - Fun WIth a Pencil
            [description] => 
        )

[.. cut for brevity ..]

    [result 20] => Array
        (
            [doc_id] => 515437
            [title] => Andrew Loomis - Fun With A Pencil
            [description] => 
        )

*/