PHP Social Auth Library
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples/base
lib/Social
.gitattributes
.gitignore
README.md
composer.json

README.md

php-social

The library to make work with social networks easy. They can auth with OAuth 2.0 or OAuth 1+ protocols and retrieve user profile info. Support Vkontakte, Facebook, Twitter, Github, MailRu. Works with PHP 5.3.3 or later.

Usage

You can see base example.

Auth in vk.com:

// config.php
$APP_ID_VK = -1; // app id
$APP_SECRET_VK = 'some secret code';
$APP_SCOPE_VK = ''; //some permissions
$REDIRECT_URL_VK = 'http://domain.ltd/auth_callback_vk.php';


// auth_vk.php
require __DIR__.'/config.php';
$auth = new \Social\Auth\AuthVk($APP_ID_VK, $APP_SECRET_VK, $APP_SCOPE_VK);
$url = $auth->getAuthorizeUrl($REDIRECT_URL_VK);
stopAndRedirect($url);

Now create callback file and get first api call:

// auth_callback_vk.php
require __DIR__.'/config.php';
$auth = new \Social\Auth\AuthVk($APP_ID_VK, $APP_SECRET_VK, $APP_SCOPE_VK);
$token = $auth->authenticate($_REQUEST, $REDIRECT_URL_VK);

if($token == null){
    var_dump($auth->getError());
    //exit
}

//call api with access_token
$api = new \Social\Api\ApiVk($token);
$user = $api->getProfile();

//use user data

// $user->id
// $user->firstName
// $user->lastName
// $user->nickname
// $user->screenName
// $user->photoUrl
// $user->photoBigUrl
// ...

Installation

The recommended way to install php-social is through Composer. Just create a composer.json file and run the php composer.phar install command to install it:

{
    "require": {
        "itlessons/php-social": "*"
    }
}

Alternatively, you can download the php-social.zip file and extract it.

Read