4shared 中文文档教程

发布于 10年前 浏览 38 项目主页 更新于 3年前

4Shared-API / fourShared API (www.4shared.com)

这是使用 NodeJS 使用 4Shared API 的 API 包装库。请访问以下链接了解更多信息 4Shared_Docs

  • All API's implemented.
  • All API's are only for Authenticated, Except FileSearch.
Search, Filter & Sorting:

类别: - 音乐-1 - 视频 - 2 - 照片 - 3 - 档案 - 4 - 书籍/办公室 - 5 - 程序 - 6 - 网络 - 7 - 手机 - 8 - Android - 10

Libarary 的示例使用也在示例中 文件夹。 只需在那里替换您的密钥,即可开始测试应用程序。

Version

1.0.0

Tech

4Shared 使用 OAuth 库进行身份验证和更新 授权

  • OAuth - Authentication & Authorization
  • Grunt - for JS Hint & Testing
  • Express - for Sample use of Lib Functionality

Installation

您需要全局安装 npm:

$ npm install -g npm

之后安装模块,如下所示,

$ npm install 4shared

Example

第一个选项卡:

var fourSharedApi = require('../index');
var express = require('express');
var app = express();
var fs = require('fs');


var fileId = "";
var rootFolder = "";
var folderID = "";
var userID= "";

var client = new fourSharedApi({
    "oauth_consumer_key": "xxxx",
    "oauth_secret_key": "xxxx",
    "callback": "http://localhost:8080/callback",
    "access_token": "optional",
    "access_secret": "optional",
    "authorized": true
});

client.on('error', function(err) {
    console.log(err);
});

client.on('connected', function(is) {
    console.log(is);
});

app.get('/start', function(req, res) {
    client.authenticate(function(err, data) {
        if (err) throw err;
        res.redirect('https://api.4shared.com/v0/oauth/authorize?oauth_token=' + data.token);
    });
});

app.get('/callback', function(req, res) {
    client.callback(function(err, data) {
        if (err) throw err;
        res.json(data);
    });
});

app.get('/filesearch', function(req, res) {
    client.fileSearch(function(err, resp, body) {
        console.log(err);
        res.send(body)
    });
});

app.get('/filesearchparams', function(req, res) {
    var queryOpts = {
        category: "2",
        query: "Sky"
    };
    client.fileSearch(queryOpts, function(err, resp, body) {
        console.log(err);
        res.send(body)
    });
});

app.get('/userinfo', function(req, res) {
    client.userInfo(function(err, resp, body) {
        console.log(err);
        rootFolder = JSON.parse(body).rootFolderId;
        userID = JSON.parse(body).id;
        res.send(body);
    });
});

app.get('/uploadFile', function(req, res) {
    var formData = {
        folderId: "2iVI6yt1",
        description: "testing",
        tags: "test",
        file: fs.createReadStream(__dirname + '/origin.js')
    };

    client.uploadFile(formData, function(err, resp, body) {
        console.log(err);
        fileId = JSON.parse(body).id;
        res.send(body);
    });
});

app.get('/updateFile', function(req, res) {
    var formData2 = {
        file: fs.createReadStream(__dirname + '/replacement.js')
    }
    console.log(fileId);
    client.updateFile(fileId, formData2, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/updateFileInfo', function(req, res) {
    var dad = {
        name: "nameisChanged"
    }
    console.log(fileId);
    client.updateFileInfo(fileId, dad, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/fileinfo', function(req, res) {
    client.getfileInfo(fileId, false, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
})

app.get('/updateUserInfo', function(req, res) {
    var data = {
        firstName: "UpdateUser",
        description: "Hi How Are Yu!!"
    };
    client.updateUserInfo(data, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/userfiles', function(req, res) {
    client.userFiles(function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/getOwnerInfo', function(req, res) {
    client.getOwnerInfo(userID, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/foldersInfo', function(req, res) {
    console.log(rootFolder);
    client.foldersInfo(rootFolder, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/childrenFolderInfo', function(req, res) {
    client.childrenFolderInfo(rootFolder, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/listFilesInFolder', function(req, res) {
    client.listFilesInFolder(rootFolder, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/createFolder', function(req, res) {
    var foldata = {
        parentId: "2iVI6yt1",
        name: "testFolder",
        description: "test Folder.."
    }
    client.createFolder(foldata, function(err, resp, body) {
        console.log(err);
        folderID = JSON.parse(body).id;
        res.send(body);
    });
});

app.get('/updateFolderInfo', function(req, res) {
    var foldata = {
        name: "testFolderUpdated",
        description: "test Folder.."
    }
    client.updateFolderInfo(folderID, foldata, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});


app.get('/deleteFolder', function(req, res) {
    client.deleteFolder(folderID, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/deleteFile', function(req, res) {
    client.deleteFile(fileId, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

var server = app.listen(8080,function(){
    console.log("Server Started");
});

Todo's

  • Write Tests
  • Add Code Comments

License

MIT

4Shared-API / fourShared API (www.4shared.com)

This is API Wrapper Library for Consuming 4Shared API usin NodeJS.Please visit the below link for more info 4Shared_Docs

  • All API's implemented.
  • All API's are only for Authenticated, Except FileSearch.
Search, Filter & Sorting:

Categories: - Music -1 - Video - 2 - Photo - 3 - Archieves - 4 - Books/Office - 5 - Programs - 6 - Web - 7 - Mobile - 8 - Android - 10

Sample use of Libarary is also, in the examples folder. Just Replace your keys there, to start testing the application.

Version

1.0.0

Tech

4Shared Uses OAuth Library for Authentication & Authorization

  • OAuth - Authentication & Authorization
  • Grunt - for JS Hint & Testing
  • Express - for Sample use of Lib Functionality

Installation

You need npm installed globally:

$ npm install -g npm

After that install the module as below,

$ npm install 4shared

Example

First Tab:

var fourSharedApi = require('../index');
var express = require('express');
var app = express();
var fs = require('fs');


var fileId = "";
var rootFolder = "";
var folderID = "";
var userID= "";

var client = new fourSharedApi({
    "oauth_consumer_key": "xxxx",
    "oauth_secret_key": "xxxx",
    "callback": "http://localhost:8080/callback",
    "access_token": "optional",
    "access_secret": "optional",
    "authorized": true
});

client.on('error', function(err) {
    console.log(err);
});

client.on('connected', function(is) {
    console.log(is);
});

app.get('/start', function(req, res) {
    client.authenticate(function(err, data) {
        if (err) throw err;
        res.redirect('https://api.4shared.com/v0/oauth/authorize?oauth_token=' + data.token);
    });
});

app.get('/callback', function(req, res) {
    client.callback(function(err, data) {
        if (err) throw err;
        res.json(data);
    });
});

app.get('/filesearch', function(req, res) {
    client.fileSearch(function(err, resp, body) {
        console.log(err);
        res.send(body)
    });
});

app.get('/filesearchparams', function(req, res) {
    var queryOpts = {
        category: "2",
        query: "Sky"
    };
    client.fileSearch(queryOpts, function(err, resp, body) {
        console.log(err);
        res.send(body)
    });
});

app.get('/userinfo', function(req, res) {
    client.userInfo(function(err, resp, body) {
        console.log(err);
        rootFolder = JSON.parse(body).rootFolderId;
        userID = JSON.parse(body).id;
        res.send(body);
    });
});

app.get('/uploadFile', function(req, res) {
    var formData = {
        folderId: "2iVI6yt1",
        description: "testing",
        tags: "test",
        file: fs.createReadStream(__dirname + '/origin.js')
    };

    client.uploadFile(formData, function(err, resp, body) {
        console.log(err);
        fileId = JSON.parse(body).id;
        res.send(body);
    });
});

app.get('/updateFile', function(req, res) {
    var formData2 = {
        file: fs.createReadStream(__dirname + '/replacement.js')
    }
    console.log(fileId);
    client.updateFile(fileId, formData2, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/updateFileInfo', function(req, res) {
    var dad = {
        name: "nameisChanged"
    }
    console.log(fileId);
    client.updateFileInfo(fileId, dad, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/fileinfo', function(req, res) {
    client.getfileInfo(fileId, false, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
})

app.get('/updateUserInfo', function(req, res) {
    var data = {
        firstName: "UpdateUser",
        description: "Hi How Are Yu!!"
    };
    client.updateUserInfo(data, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/userfiles', function(req, res) {
    client.userFiles(function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/getOwnerInfo', function(req, res) {
    client.getOwnerInfo(userID, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/foldersInfo', function(req, res) {
    console.log(rootFolder);
    client.foldersInfo(rootFolder, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/childrenFolderInfo', function(req, res) {
    client.childrenFolderInfo(rootFolder, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/listFilesInFolder', function(req, res) {
    client.listFilesInFolder(rootFolder, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/createFolder', function(req, res) {
    var foldata = {
        parentId: "2iVI6yt1",
        name: "testFolder",
        description: "test Folder.."
    }
    client.createFolder(foldata, function(err, resp, body) {
        console.log(err);
        folderID = JSON.parse(body).id;
        res.send(body);
    });
});

app.get('/updateFolderInfo', function(req, res) {
    var foldata = {
        name: "testFolderUpdated",
        description: "test Folder.."
    }
    client.updateFolderInfo(folderID, foldata, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});


app.get('/deleteFolder', function(req, res) {
    client.deleteFolder(folderID, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

app.get('/deleteFile', function(req, res) {
    client.deleteFile(fileId, function(err, resp, body) {
        console.log(err);
        res.send(body);
    });
});

var server = app.listen(8080,function(){
    console.log("Server Started");
});

Todo's

  • Write Tests
  • Add Code Comments

License

MIT

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文