turanct / showpad-api
Showpad API包装器
1.3.0
2015-12-29 13:24 UTC
This package is auto-updated.
Last update: 2024-08-28 22:53:42 UTC
README
这是一个简单的PHP包装器,用于Showpad API。它为API v2版本构建,目前尚不完整。
您可以在以下链接找到Showpad网站:这里
- 特性
我们支持的功能尚不完整。添加新功能应该很容易,如果您这样做,请发送拉取请求!
- 基本配置对象。有一个接口,您可以使用它创建例如实现
ConfigInterface
的ConfigDatabase
对象,这样事情仍然可以正常工作。 - OAuth2身份验证
- 一些API方法(这里没有完整的功能...)
- 设置
2.1 Composer
请使用Composer来自动加载Showpad API包装器!我不鼓励使用其他方法。
composer.json
{ "require": { "turanct/showpad-api-guzzle": "~0.1", "turanct/showpad-api": "~1.0" } }
turanct/showpad-api-guzzle
库是guzzle的适配器。将来应该会有其他适配器可用,或者您也可以自己创建。
2.2 身份验证
SHOWPAD_URL
API URL,例如https://yournamehere.showpad.biz/api/v2
SHOWPAD_APP_ID
应用程序的客户端IDSHOWPAD_APP_SECRET
应用的密钥
2.2.1 步骤 1
<?php // Create a config object $config = new Showpad\ConfigBasic(SHOWPAD_URL, SHOWPAD_APP_ID, SHOWPAD_APP_SECRET, null, null); // Create a client object $guzzleClient = new Guzzle\Http\Client(); $client = new Showpad\GuzzleAdapter($guzzleClient); // Create an Authentication object, using the config $auth = new Showpad\Authentication($config, $client); // Get the url for the first step of the OAuth2 process $authorizeUrl = $auth->authenticationStart(SHOWPAD_AUTH_REDIRECT_URL); // You should now redirect your user to this url, and let him authorize the application. // If they authorized the application, you'll get a GET parameter 'code', which you'll need for step 2.
2.2.2 步骤 2
<?php // Create a config object $config = new Showpad\ConfigBasic(SHOWPAD_URL, SHOWPAD_APP_ID, SHOWPAD_APP_SECRET, null, null); // Create a client object $guzzleClient = new Guzzle\Http\Client(); $client = new Showpad\GuzzleAdapter($guzzleClient); // Create an Authentication object, using the config $auth = new Showpad\Authentication($config, $client); // Get the OAuth2 tokens using the code from the first step of the OAuth2 process $tokens = $auth->authenticationFinish($codeFromFirstStep, SHOWPAD_AUTH_REDIRECT_URL); // If everything went ok, $tokens is now an associative array with keys 'access_token' and 'refresh_token' // You should store these keys to be able to do requests in the future.
请注意,access_token
仅有效一小时。您需要使用刷新流程来获取新的访问令牌。
2.2.3 刷新流程
<?php // Create a config object $config = new Showpad\ConfigBasic( SHOWPAD_URL, SHOWPAD_APP_ID, SHOWPAD_APP_SECRET, $tokens['access_token'], $tokens['refresh_token'] ); // Create a client object $guzzleClient = new Guzzle\Http\Client(); $client = new Showpad\GuzzleAdapter($guzzleClient); // Create an Authentication object, using the config $auth = new Showpad\Authentication($config, $client); // Request new tokens $tokens = $auth->refreshTokens(); // If everything went ok, $tokens is now an associative array with the keys 'access_token' and 'refresh_token', // containing fresh tokens. You should store these keys to be able to do requests in the future.
请注意,access_token
仅有效一小时。您需要使用刷新流程来获取新的访问令牌。
- 用法
<?php // Create a config object $config = new Showpad\ConfigBasic( SHOWPAD_URL, SHOWPAD_APP_ID, SHOWPAD_APP_SECRET, $tokens['access_token'], $tokens['refresh_token'] ); // Create a client object $guzzleClient = new Guzzle\Http\Client(); $client = new Showpad\GuzzleAdapter($guzzleClient); // Create an Authentication object, using the config $auth = new Showpad\Authentication($config, $client); // Create a showpad client. This client contains all possible api methods. $client = new Showpad\Client($auth); // You can now e.g. upload a file to showpad: $client->assetsAdd($pathToFile);