开发者

Simple PHP and oAuth Library [closed]

开发者 https://www.devze.com 2023-04-03 06:07 出处:网络
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
开发者_如何学Python

Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.

Closed 9 years ago.

Improve this question

I'm looking for a basic oAuth library for PHP, something that I can just pass a consumer key, a secret key, and a URL to request the token, (and a callback) where it will just return an oAuth Token. The main feature it needs is to be useable accross various social networks. currently I have a massive wrapper for Twitter, a massive wrapper for facebook and another for Linked in etc, which could be replaced with one function for each site, and a basic oAuth site.


There are no such library at the moment. You have the oauth-php and oauth2-php library but they're not "simple", the good part is they manage their token themselves. They don't like overlong tokens (like Yahoo's) which can be a big problem.

Also, some functions of the Microsoft API are not available in their 5.0 version anymore, meaning you have to use their old API which implement their own Oauth protocol (all oauth_* parameters are named wrap_*).

Edit: you can check the HybridAuth project which implements the login part (not the whole APIs) but should give you a good starter.


I actually came across this question myself and ended up building an OAuth library after looking at all the choices I had. Here's some sample code for calling Twitter's API:

use ohmy\Auth1;

# start a session to save oauth data in-between redirects
session_start();

# initialize 3-legged oauth
$twitter = Auth1::init(3);

# configuration
$twitter->set('key', 'your consumer key')
        ->set('secret', 'your consumer secret')
        ->set('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')
        ->finally(session_destroy);

# 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>';
        });

The library works with Twitter, Facebook, and LinkedIn. You can check it out at: https://github.com/sudocode/ohmy-auth

0

精彩评论

暂无评论...
验证码 换一张
取 消