<?php require_once __DIR__ . '/../vendor/autoload.php'; /* * Copyright (c) 2014, Yahoo! Inc. All rights reserved. * Copyrights licensed under the New BSD License. * See the accompanying LICENSE file for terms. */ use ohmy\Auth; # initialize OAuth2 3-legged $instagram = Auth::init(array('id' => 'your client id', 'secret' => 'your client secret', 'redirect' => 'your redirect uri', 'scope' => 'wl.basic'))->authorize('https://login.live.com/oauth20_authorize.srf')->access('https://login.live.com/oauth20_token.srf')->finally(function ($data) use(&$access_token) { $access_token = $data['access_token']; }); # test GET call $instagram->GET("https://apis.live.net/v5.0/me?access_token={$access_token}")->then(function ($response) { echo '<pre>'; var_dump($response->json()); echo '</pre>'; });
<?php require_once __DIR__ . '/../vendor/autoload.php'; /* * Copyright (c) 2014, Yahoo! Inc. All rights reserved. * Copyrights licensed under the New BSD License. * See the accompanying LICENSE file for terms. */ use ohmy\Auth; # initialize OAuth2 3-legged $google = Auth::init(array('id' => 'your client id', 'secret' => 'your client secret', 'redirect' => 'your redirect uri', 'scope' => 'profile'))->authorize('https://accounts.google.com/o/oauth2/auth')->access('https://accounts.google.com/o/oauth2/token')->finally(function ($data) use(&$access_token) { $access_token = $data['access_token']; }); # test GET call $google->GET("https://www.googleapis.com/plus/v1/people/me?access_token={$access_token}")->then(function ($response) { echo '<pre>'; var_dump($response->text); echo '</pre>'; });
<?php require_once __DIR__ . '/../vendor/autoload.php'; /* * Copyright (c) 2014, Yahoo! Inc. All rights reserved. * Copyrights licensed under the New BSD License. * See the accompanying LICENSE file for terms. */ use ohmy\Auth; # initialize OAuth2 3-legged $linkedin = Auth::init(array('id' => 'your client id', 'secret' => 'your client secret', 'redirect' => 'your redirect uri'))->authorize('https://www.linkedin.com/uas/oauth2/authorization')->access('https://www.linkedin.com/uas/oauth2/accessToken')->finally(function ($data) use(&$access_token) { $access_token = $data['access_token']; }); # test GET call $linkedin->GET("https://api.linkedin.com/v1/people/~?oauth2_access_token={$access_token}")->then(function ($response) { echo '<pre>'; var_dump($response->text); echo '</pre>'; });
<?php require_once __DIR__ . '/../vendor/autoload.php'; /* * Copyright (c) 2014, Yahoo! Inc. All rights reserved. * Copyrights licensed under the New BSD License. * See the accompanying LICENSE file for terms. */ use ohmy\Auth; # initialize OAuth1 3-legged $yahoo = Auth::init(array('key' => 'your consumer key', 'secret' => 'your consumer secret', 'callback' => 'your callback url'))->request('https://api.login.yahoo.com/oauth/v2/get_request_token')->authorize('https://api.login.yahoo.com/oauth/v2/request_auth')->access('https://api.login.yahoo.com/oauth/v2/get_token'); $yahoo->GET('https://query.yahooapis.com/v1/yql?q=select%20*%20from%20social.contacts%20where%20guid%3Dme%3B&format=json&diagnostics=true&callback=')->then(function ($response) { echo '<pre>'; var_dump($response->json()); echo '</pre>'; });
<?php require_once __DIR__ . '/../vendor/autoload.php'; /* * Copyright (c) 2014, Yahoo! Inc. All rights reserved. * Copyrights licensed under the New BSD License. * See the accompanying LICENSE file for terms. */ use ohmy\Auth; # initialize OAuth1 2-legged $termie = Auth::init(array('oauth_consumer_key' => 'key', 'oauth_consumer_secret' => 'secret'))->request('http://term.ie/oauth/example/request_token.php')->access('http://term.ie/oauth/example/access_token.php')->finally(function ($data) use(&$token, &$secret) { $token = $data['oauth_token']; $secret = $data['oauth_token_secret']; }); # test GET call $termie->GET('http://term.ie/oauth/example/echo_api.php?method=get')->then(function ($response) { var_dump($response->text()); }); # test POST call $termie->POST('http://term.ie/oauth/example/echo_api.php', array('method' => 'post'))->then(function ($response) { var_dump($response->text()); }); # test revival $termie2 = Auth::init(array('oauth_consumer_key' => 'key', 'oauth_consumer_secret' => 'secret'))->access($token, $secret)->GET('http://term.ie/oauth/example/echo_api.php?method=revive')->then(function ($response) { var_dump($response->text()); });
<?php require_once __DIR__ . '/../vendor/autoload.php'; /* * Copyright (c) 2014, Yahoo! Inc. All rights reserved. * Copyrights licensed under the New BSD License. * See the accompanying LICENSE file for terms. */ use ohmy\Auth; # initialize OAuth1 3-legged $fitbit = Auth::init(array('key' => 'your consumer key', 'secret' => 'your consumer secret', 'callback' => 'your callback url'))->request('http://api.fitbit.com/oauth/request_token')->authorize('http://www.fitbit.com/oauth/authorize')->access('http://api.fitbit.com/oauth/access_token')->finally(function ($data) use(&$user_id) { $user_id = $data['encoded_user_id']; }); # test GET call $fitbit->GET("https://api.fitbit.com/1/user/{$user_id}/profile.json")->then(function ($response) { echo '<pre>'; var_dump($response->json()); echo '</pre>'; });
<?php require_once __DIR__ . '/../vendor/autoload.php'; /* * Copyright (c) 2014, Yahoo! Inc. All rights reserved. * Copyrights licensed under the New BSD License. * See the accompanying LICENSE file for terms. */ use ohmy\Auth; # initialize OAuth1 3-legged $twitter = Auth::init(array('key' => 'your consumer key', 'secret' => 'your consumer secret', 'callback' => 'your callback url'))->request('https://api.twitter.com/oauth/request_token')->authorize('https://api.twitter.com/oauth/authorize')->access('https://api.twitter.com/oauth/access_token'); # test GET call $twitter->GET('https://api.twitter.com/1.1/statuses/home_timeline.json', array('count' => 5))->then(function ($response) { echo '<pre>'; var_dump($response->json()); echo '</pre>'; });
/** * @dataProvider provider */ public function testRunProtocolReturn($clientCredentials, $expected) { $protocol = Auth::init($clientCredentials); $this->assertInstanceOf($expected, $protocol); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; /* * Copyright (c) 2014, Yahoo! Inc. All rights reserved. * Copyrights licensed under the New BSD License. * See the accompanying LICENSE file for terms. */ use ohmy\Auth; # initialize OAuth2 3-legged $facebook = Auth::init(array('id' => 'your client id', 'secret' => 'your client secret', 'redirect' => 'your redirect uri', 'scope' => 'read_stream'))->authorize('https://www.facebook.com/dialog/oauth')->access('https://graph.facebook.com/oauth/access_token')->finally(function ($data) use(&$access_token) { $access_token = $data['access_token']; }); # test GET call $facebook->GET("https://graph.facebook.com/me/home?access_token={$access_token}")->then(function ($response) { echo '<pre>'; var_dump($response->json()); echo '</pre>'; });
<?php require_once __DIR__ . '/../vendor/autoload.php'; /* * Copyright (c) 2014, Yahoo! Inc. All rights reserved. * Copyrights licensed under the New BSD License. * See the accompanying LICENSE file for terms. */ use ohmy\Auth; # initialize OAuth2 3-legged $github = Auth::init(array('id' => 'your client id', 'secret' => 'your client secret', 'redirect' => 'your redirect uri'))->authorize('https://github.com/login/oauth/authorize')->access('https://github.com/login/oauth/access_token')->finally(function ($data) use(&$access_token) { $access_token = $data['access_token']; }); # access github api $github->GET("https://api.github.com/user?access_token={$access_token}", null, array('User-Agent' => 'ohmy-auth'))->then(function ($response) { echo '<pre>'; var_dump($response->json()); echo '</pre>'; });
<?php require_once __DIR__ . '/../vendor/autoload.php'; /* * Copyright (c) 2014, Yahoo! Inc. All rights reserved. * Copyrights licensed under the New BSD License. * See the accompanying LICENSE file for terms. */ use ohmy\Auth; # initialize OAuth2 3-legged $instagram = Auth::init(array('id' => 'your client id', 'secret' => 'your client secret', 'redirect' => 'your redirect uri', 'scope' => 'basic'))->authorize('https://api.instagram.com/oauth/authorize')->access('https://api.instagram.com/oauth/access_token')->finally(function ($data) use(&$access_token) { $access_token = $data['access_token']; }); # test GET call $instagram->GET("https://api.instagram.com/v1/users/self/feed/?access_token={$access_token}")->then(function ($response) { echo '<pre>'; var_dump($response->json()); echo '</pre>'; });