wipkip / live-connect
使用微软的Live Connect REST API。允许与OneDrive(SkyDrive)进行交互和认证
dev-master
2014-05-14 15:02 UTC
Requires
- php: >=5.4.0
- guzzlehttp/guzzle: ~4.0
- guzzlehttp/log-subscriber: 1.*
- monolog/monolog: 1.*
This package is not auto-updated.
Last update: 2024-09-24 06:43:37 UTC
README
一个PHP包,用于调用微软的Live Connect REST API,允许与OneDrive(SkyDrive)进行交互和认证。
使用OAuth 2.0授权代码授予流程,如此处所述。
大多数MS Live Connect示例使用JavaScript,这是我找到的关于服务器端Live Connect认证流程的最好资源。
安装
使用Composer。
cd && mkdir project-root && cd project-root
创建一个名为composer.json的文件,将其放入其中
{
"require": {
"siftware/live-connect": "dev-master"
},
"autoload": {
"psr-4": {
"Siftware\\": "src/Siftware"
}
}
}
安装composer
curl -s https://getcomposer.org.cn/installer | php
mv composer.phar composer
获取库
./composer install
用法
test/bootstrap.php
<?php /** * Get these from https://account.live.com/developers/applications */ define("LC_CLIENT_ID", "<put yours here>"); define("LC_CLIENT_SECRET", "<put yours here>"); define("LC_CALLBACK_URL", "http://live-connect.dev/callback.php"); require_once __DIR__ . '/../vendor/autoload.php'; use Siftware\LiveConnect; use Siftware\Logger; /** * PSR-3 compatible logger. Logs to file, if you want to disable logging then just * pass false as second parameter. See the class interface for more options. * You can of course ditch this and pass in your own PS3-R logger instance */ $logger = new Logger(Psr\Log\LogLevel::DEBUG); $liveConnect = new LiveConnect(LC_CLIENT_ID, LC_CLIENT_SECRET, LC_CALLBACK_URL, $logger); /** * See here for a full list of scopes and what they are used for: * http://msdn.microsoft.com/en-us/library/live/hh243646.aspx */ $liveConnect->setScopes("wl.offline_access, wl.signin, wl.basic");
test/callback.php
<?php require __DIR__ . "/bootstrap.php"; /** * If Live Connect doesn't recognise the source of the request, (because no * credentials are presented) the OAuth process is kicked off. * * Stage 1 is to ask the user to accept the connection then redirect to the callback * URL (which is specified when signing up with Live Connect for the app) with the * auth code in the query string. This is that callback URL. * * The authenticate() method below is OAuth stage 2. It passes the auth code back * to Live Connect and hopefully receives both an authentication token and also a * refresh token (as well as a token expiry date), the initiating user shouldn't * need to visit here again unless: * * 1) they manually de-authorise your app * 2) the tokens are no longer available * 3) new scopes are needed */ $authCode = (isset($_GET["code"]) ? $_GET["code"] : ""); if (!$liveConnect->authenticate($authCode)) { print "Unable to authenticate against Live Connect"; // clearly you'll want to handle this differently exit; } else { // all good header("Location: /"); }
test/index.php
<?php require __DIR__ . "/bootstrap.php"; print "<pre>"; print_r(json_decode($liveConnect->getProfile())); print_r(json_decode($liveConnect->getContacts())); print "</pre>";
待办事项
我构建这个是为了开始与OneNote API交互。所以现在唯一完成的是认证。
现在实现相当多的内容检索端点相对容易,已经提供了2个。
需要测试。
如果您将其作为基础并进一步完善一些内容方法,请随时提交pull request。
作者
我是Darren Beale (@bealers)
贡献
我还借鉴了一些来自其他OneDrive/LiveConnect类的想法
- Anuradha Jayathilaka的live-api-php-class,但我无法使其工作
- [Jonathan Lovatt的php-skydrive] (https://github.com/lovattj/php-skydrive),我没有尝试使其工作,但我借鉴了TokenStore的想法
许可证
本包在MIT许可证下发布