Skip to content

Commit

Permalink
Merge pull request #10 from maddie/master
Browse files Browse the repository at this point in the history
Fix API Secret, README, grammatic errors
  • Loading branch information
oott123 committed Oct 20, 2013
2 parents 6771162 + e22d30f commit c4f61e4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 51 deletions.
63 changes: 30 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,45 @@ Linux (or cygwin) with php & curl installed.

敲下命令之后会进入初始化流程,这里分段详述设置方法。

> Uploader initialization will be begin. If you have already configured
> the uploader before, your old settings will be overwritten.
> Uploader initialization will be begin. If you have already configured the uploader before, your old settings will be overwritten.
> Continue? [y/N] y
确认初始化。如果之前有初始化过,那么以前的配置将会被覆盖。

> Please enter your PSC App API Key. You can get this key by visiting
> http://developer.baidu.com/dev#/create
> If you already created an app, you can visit http://developer.baidu.com/console#/app and get it in your app's info.
> If you don't want to bother creating an app, you can press Enter to use the demo API Key.
> Doing so (without your own API Key/Secret) will cause the access-token expire every 30 days, and you'll have to
> re-initialize when it expires.
> Please enter your PSC App API Key. You can get this key by visiting http://developer.baidu.com/dev#/create
> If you have already created an app, you can visit http://developer.baidu.com/console#/app and get it in your app's info.
> If you don't want to bother creating an app, you can press Enter to use the demo API Key.
> Doing so (without your own API Key/Secret) will cause the access-token to expire every 30 days, and you'll have to re-initialize when it expires.
> App API KEY [uFBSHEwWE6DD94SQx9z77vgG] :
第一步,输入App key。这里需要输入一个有PCS权限的API KEY,如果没有的话直接敲回车就好了,这里会默认使用内置的一组app key,app secret和app folder name,所以只要敲下回车就能直接跳到第四步。如果你没有App secret(例如使用L6g70tBRRIXLsY0Z3HwKqlRE这个Key时),只能获取一个有效期为一个月的access token。如果有一个有PSC权限的API KEY和secret,那么就能获得一个有效期为10年的refresh token,以便长期使用。

> App API Key has been set to uFBSHEwWE6DD94SQx9z77vgG .
> Please enter your Baidu PSC App API Secret. If you have no idea what it is, keep it blank.
> App API Key has been set to uFBSHEwWE6DD94SQx9z77vgG .
> Please enter your Baidu PSC App API Secret. If you have no idea what it is, keep it blank.
> App API SECRET [] :
第二步,输入App secret。如果输入了app secret,将会转到device code模式验证;或者直接输入回车使用oob模式验证。先直接回车:

> Please enter your app's folder name. You can choose to input this later in the file [ /root/_bpcs_files_/config/appname ].
> ** Why do I have to enter the app's folder name? Please check the FAQs. **
> If your app's name has Chinese characters, please ensure that your client supports UTF-8 encoding.
> Below are some Chinese characters for testing. Please make sure that you can read them before you enter Chinese here.
> 这里是一些中文字符。
> If you can't read the characters above, please press Enter and change it manually within the file [ /root/_bpcs_files_/config/appname ].
> If you have Enter the key [L6g70tBRRIXLsY0Z3HwKqlRE] (by default) , just press Enter.
> Please enter your app's folder name. You can choose to input this later in the file [ /root/_bpcs_files_/config/appname ].
> ** Why do I have to enter the app's folder name? Please check the FAQs. **
> If your app's name has Chinese characters, please ensure that your client supports UTF-8 encoding.
> Below are some Chinese characters for testing. Please make sure that you can read them before you enter Chinese here.
> 这里是一些中文字符。
> If you can't read the characters above, please press Enter and change it manually within the file [ /root/_bpcs_files_/config/appname ].
> If you have Enter the key [L6g70tBRRIXLsY0Z3HwKqlRE] (by default) , just press Enter.
> App Name [pcstest_oauth] :
第三步,这里需要输入app folder name,也就是你申请API时填写的文件夹名字。详情见FAQ 2。因为是使用的默认的key,所以直接回车即可。

> In the next step, you'll have to grab the access_token generated by Baidu.
> You can check out this link for more information on this procedure.
> http://developer.baidu.com/wiki/index.php?title=docs/pcs/guide/usage_example
>
> Easy Guide:
> 1. Visit https://openapi.baidu.com/oauth/2.0/authorize?response_type=token&client_id=$appkey&redirect_uri=oob&scope=netdisk
> 2. After the page is being redirected (it should show something like OAuth 2.0), copy the current URL to your favorite text editor.
> 3. Grab the access_token part, take only the part between "access_token=" and the next "&" symbol (without quotes).
> 4. Copy it and paste here, then press Enter.
> In the next step, you'll have to grab the access_token generated by Baidu.
> You can check out this link for more information on this procedure:
> http://developer.baidu.com/wiki/index.php?title=docs/pcs/guide/usage_example
>
> Easy Guide:
> 1. Visit https://openapi.baidu.com/oauth/2.0/authorize?response_type=token&client_id=$appkey&redirect_uri=oob&scope=netdisk
> 2. After the page is being redirected (it should show something like OAuth 2.0), copy the current URL to your favorite text editor.
> 3. Grab the access_token part, take only the part between "access_token=" and the next "&" symbol (without quotes).
> 4. Copy it and paste here, then press Enter.
> access_token[] :
第四步,获取access token。在浏览器中打开上述URL( https://openapi.baidu.com/oauth/2.0/authorize?response_type=token&client_id=L6g70tBRRIXLsY0Z3HwKqlRE&redirect_uri=oob&scope=netdisk ),进行授权。
Expand All @@ -83,18 +80,18 @@ Linux (or cygwin) with php & curl installed.

如果第三步输入app secret的时候没有留空,将会得到下面的消息:

> Launch your favorite web browser and visit https://openapi.baidu.com/device
> Input 12abcxyz as the user code if asked.
> Launch your favorite web browser and visit https://openapi.baidu.com/device
> Input 12abcxyz as the user code if asked.
> After granting access to the application, come back here and press Enter to continue.
来到这里,打开浏览器访问 https://openapi.baidu.com/device ,在“请输入设备上显示的用户授权码:”文本框中输入上面显示的授权码(这里是`12abcxyz`),并点击继续。
看到网页上显示“请返回设备继续操作!”后,返回ssh上按下回车后,即可继续。

> curl -X GET -k -L "...."
> % Total % Received % Xferd Average Speed Time Time Time Current
> Dload Upload Total Spent Left Speed
> 0 62 0 62 0 0 40 0 --:--:-- 0:00:01 --:--:-- 235
> Access Granted. Your Storage Status: 0.06G/115.00G (0.05%)
> curl -X GET -k -L "...."
> % Total % Received % Xferd Average Speed Time Time Time Current
> Dload Upload Total Spent Left Speed
> 0 62 0 62 0 0 40 0 --:--:-- 0:00:01 --:--:-- 235
> Access Granted. Your Storage Status: 0.06G/115.00G (0.05%)
> Enjoy!
你所看到的输出可能和这里给出的不一样,但是只要看到了存储空间的剩余量,和【Have fun !】提示,即说明成功初始化。
Expand Down
6 changes: 3 additions & 3 deletions _bpcs_files_/common.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ function cmd($cfe) {
}
function do_api($url,$param,$method = 'POST'){
if($method == 'POST'){
$cmd = "curl -X POST -k -L --data \"$param\" \"$url\"";
$cmd = "curl -X POST -k -L --silent --data \"$param\" \"$url\"";
}else{
$cmd = "curl -X $method -k -L \"$url?$param\"";
$cmd = "curl -X $method -k -L --silent \"$url?$param\"";
}

return cmd($cmd);
Expand All @@ -104,4 +104,4 @@ function error_handle($errno, $errstr, $errfile, $errline){
}
return true;
}
set_error_handler("error_handle");
set_error_handler("error_handle");
20 changes: 10 additions & 10 deletions _bpcs_files_/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ function du_init($quickinit = false){
//正常初始化
echo <<<EOF
Please enter your PSC App API Key. You can get this key by visiting http://developer.baidu.com/dev#/create
If you already created an app, you can visit http://developer.baidu.com/console#/app and get it in your app\'s info.
If you don\'t want to bother creating an app, you can press Enter to use the demo API Key.
Doing so (without your own API Key/Secret) will cause the access-token expire every 30 days, and you\'ll have to
If you have already created an app, you can visit http://developer.baidu.com/console#/app and get it in your app's info.
If you don't want to bother creating an app, you can press Enter to use the demo API Key.
Doing so (without your own API Key/Secret) will cause the access-token to expire every 30 days, and you'll have to
re-initialize when it expires.
EOF;
Expand All @@ -35,7 +35,7 @@ function du_init($quickinit = false){
Please enter your Baidu PSC App API Secret. If you have no idea what it is, keep it blank.
EOF;
echo 'App API SECRET [] :';
echo 'App API SECRET ['.BPCSU_SEC.'] :';
$appsec = getline();
}
file_put_contents(CONFIG_DIR.'/appsec',$appsec);
Expand All @@ -45,12 +45,12 @@ function du_init($quickinit = false){
$appname = 'bpcs_uploader';
}else{
echo <<<EOF
Please enter your app\'s folder name. You can choose to input this later in the file [ $prepathfile ].
** Why do I have to enter the app\'s folder name? Please check the FAQs. **
If your app\'s name has Chinese characters, please ensure that your client supports UTF-8 encoding.
Please enter your app's folder name. You can choose to input this later in the file [ $prepathfile ].
** Why do I have to enter the app's folder name? Please check the FAQs. **
If your app's name has Chinese characters, please ensure that your client supports UTF-8 encoding.
Below are some Chinese characters for testing. Please make sure that you can read them before you enter Chinese here.
这里是一些中文字符。
If you can\'t read the characters above, please press Enter and change it manually within the file [ $prepathfile ].
If you can't read the characters above, please press Enter and change it manually within the file [ $prepathfile ].
EOF;
echo 'App\'s Folder Name [] : ';
Expand Down Expand Up @@ -117,14 +117,14 @@ function du_oauth_device($appkey,$appsec){
}
function do_oauth_token($appkey){
echo <<<EOF
In the next step, you\'ll have to grab the access_token generated by Baidu.
In the next step, you'll have to grab the access_token generated by Baidu.
You can check out this link for more information on this procedure.
http://developer.baidu.com/wiki/index.php?title=docs/pcs/guide/usage_example
Easy Guide:
1. Visit https://openapi.baidu.com/oauth/2.0/authorize?response_type=token&client_id=$appkey&redirect_uri=oob&scope=netdisk
2. After the page is being redirected (it should show something like OAuth 2.0), copy the current URL to your favorite text editor.
3. Grab the access_token part, take only the part between \"access_token=\" and the next \"&\" symbol (without quotes).
3. Grab the access_token part, take only the part between "access_token=" and the next "&" symbol (without quotes).
4. Copy it and paste here, then press Enter.
EOF;
Expand Down
10 changes: 5 additions & 5 deletions bpcs_uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
//欢迎信息
echo <<<EOF
===========================Baidu PCS Uploader===========================
usage : $argv[0] init|quickinit|quota
usage : $argv[0] upload|download path_local path_remote
usage : $argv[0] delete path_remote
usage : $argv[0] uploadbig path_local path_remote [slice_size(default:1073741824)] [temp_dir(def:/tmp/)]
usage : $argv[0] fetch path_remote path_to_fetch
Usage: $argv[0] init|quickinit|quota
Usage: $argv[0] upload|download path_local path_remote
Usage: $argv[0] delete path_remote
Usage: $argv[0] uploadbig path_local path_remote [slice_size(default:1073741824)] [temp_dir(def:/tmp/)]
Usage: $argv[0] fetch path_remote path_to_fetch
========================================================================
EOF;
Expand Down

0 comments on commit c4f61e4

Please sign in to comment.