Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 68 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,96 @@
php-social
# php-social

> itlessons/php-social

==========

## Brief

-----

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
## Usage

-----

You can see [base example](https://github.com/itlessons/php-social/tree/master/examples/base).

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';

```php
// 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);
// 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
```php
// 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][_Composer]. Just create a
``composer.json`` file and run the ``php composer.phar install`` command to
The recommended way to install php-social is through [Composer](http://getcomposer.org). Just create a
`composer.json` file and run the `php composer.phar install` command to
install it:

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

Or you can use the console command from your project root folder:

Alternatively, you can download the [php-social.zip][_php-social.zip] file and extract it.
```sh
$ composer require itlessons/php-social
```

Alternatively, you can download the [php-social.zip](https://github.com/itlessons/php-social/archive/master.zip) file and extract it.

Read
----

* [Авторизация с помощью OAuth 2.0 в Вконтакте, Моем мире и Facebook] (http://www.itlessons.info/php/auth-with-oauth2-in-vk-mailru-facebook/)
* [Авторизация на вашем сайте с помощью Github] (http://www.itlessons.info/php/auth-with-oauth2-in-github/)
* [Авторизация и работа с Twitter Api через OAuth] (http://www.itlessons.info/php/twitter-oauth-login-and-api/)

* [Авторизация с помощью OAuth 2.0 в Вконтакте, Моем мире и Facebook](http://www.itlessons.info/php/auth-with-oauth2-in-vk-mailru-facebook/)
* [Авторизация на вашем сайте с помощью Github](http://www.itlessons.info/php/auth-with-oauth2-in-github/)
* [Авторизация и работа с Twitter Api через OAuth](http://www.itlessons.info/php/twitter-oauth-login-and-api/)

[_Composer]: http://getcomposer.org
[_php-social.zip]: https://github.com/itlessons/php-social/archive/master.zip