PHP Classes

FreedomCore PHP VK API: Authorize and call VK API on behalf of its users

Recommend this page to a friend!
  Info   View files Example   View files View files (18)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 109 This week: 1All time: 9,633 This week: 571Up
Version License PHP version Categories
freedomcore-vk-api 1.0.5Shareware5.6PHP 5, User Management, Web services, S...
Description 

Author

This package can authorize and call VK API on behalf of its users.

It can redirect the current user to the VK authorization page to obtain a OAuth access token to access the API with given scopes.

The class can also perform several types of API calls using the obtained token to manage the user account, data storage, documents, groups and users. It checks for required scope before executing API call.

Picture of Ivan Zhivolupov
  Performance   Level  
Name: Ivan Zhivolupov <contact>
Classes: 1 package by
Country: United Kingdom
Age: ???
All time rank: 4383190 in United Kingdom
Week rank: 420 Up10 in United Kingdom Up

Example

<?php
require('header.php');

if(isset(
$_SESSION['access_token'])) {
    if(
$VKObject->isAuthorized()){
       
$VKUsers = new \FreedomCore\VK\API\VKUsers($VKObject);
       
$searchUsers = $VKUsers->get(['{ID_ONE}', '{ID_TWO'}, '{ID_N}'])
        echo
"<pre>";
       
print_r($searchUsers);
        echo
"</pre>";
    } else {
      
header('Location: /login.php');
    }
} else {
   
header('Location: /login.php');
}


Details

[PHP] FreedomCore VK API

Build Status Scrutinizer Code Quality Latest Stable Version Total Downloads Downloads Month License

A PHP VK API Client based on official VK API Documentation

Table of Contents

Introduction

This is a pure PHP implementation of VK API Client library. It can be easy extended by adding additional resource classes to API folder.

Pros: - Can authorize users with specific scope - Can check for required scope before executing API call - Works with: Users, Groups, DataStorage, Account and Documents APIs - Easy to modify - Easy to use

This code is available on Github. Pull requests are welcome.

Require this package with Composer

Install this package through Composer. Edit your project's composer.json file to require freedomcore/vk-api.

Create composer.json file

{
    "name": "nameofyourproject/nameofyourproject",
    "type": "project",
    "require": {
        "php": ">=5.6.0",
        "freedomcore/vk-api": "*"
    }
}

and run composer update

or

run this command in your command line:

composer require freedomcore/vk-api

Configuration

  1. Create New Object  
    a. To work with Library before authorization completed  
    $vkObject = new FreedomCore\VK\VKBase('{APPLICATION_ID}', '{API_SECRET}');
    
    b. To work with Library after authorization completed  
    
    $vkObject = new FreedomCore\VK\VKBase('{APPLICATION_ID}', '{API_SECRET}', '{ACCESS_TOKEN}');
  2. How to authorize user  
    a. Generate Authorization Link  
    $vkObject->getAuthorizationURL('{SCOPE}', '{CALLBACK_URL}');
    
    b. Get Access Token By Using Key From Callback  
    
    $vkObject->getAccessToken('{CODE}');
    c. Check, if user authorized  
    
    $vkObject->isAuthorized(); // returns true | false
  3. Now you can work with API

Resources

VKBase Resource

This is the main Library resource

There are 4 API Methods presented in this Resource: 1. `setAPIVersion({API_VERSION})` - Set API Version Provided By User 2. `getAuthorizationURL({SCOPE}, {CALLBACK_URL}, {RESPONSE_TYPE}, {TEST_MODE})` - Returns Authorization Link With Passed Parameters 3. `getAccessToken({CODE}, {CALLBACK_URL})` - Returns Access Token From Authorization Link 4. `isAuthorized()` - Returns User Authorization Status

VKAccount Resource

This Resource allows you to get user related data

*How to use:*

Initialize New VKAccount object:

$VKAccount = new FreedomCore\VK\API\VKAccount($vkObject);

Now you can call methods, e.g.

$getCounters = $VKAccount->getCounters();
$getApplicationPermissions = $VKAccount->getAppPermissions({USER_ID});

There are 6 API Methods presented in this Resource: 1. `getCounters({USER_FIELDS optional)` - Fetches all counters which are greater than zero (messages, videos, friends, etc) 2. `setNameInMenu({USER_ID}, {APPLICATION_NAME}` - Creates Sidebar Link to application, if user allowed it 3. `setOnline()` - Sets status to Online for 15 minutes 4. `setOffline()` - Sets status to Offline 5. `getActiveOffers({OFFSET optional}, {COUNT optional})` - Returns a list of active ads (offers) 6. `getAppPermissions()` - Gets settings of the current user in this application

VKDataStorage Resource

Missing Description

There are 3 API Methods presented in this Resource: 1. `get({KEY}, {KEYS}, {USER_ID}, {IS_GLOBAL})` - Returns a value of variable with the name set by key parameter 2. `set({KEY}, {VALUE}, {USER_ID}, {IS_GLOBAL})` - Saves a value of variable with the name set by key parameter 3. `getKeys({USER_ID}, {IS_GLOBAL}, {OFFSET optional}, {COUNT optional})` - Returns the names of all variables

VKDocuments Resource

*Attention:This Resourse is incomplete | There are 7 more methods to be added*

This Resource allows you to work with documents which are belong to user/group

*How to use:*

Initialize New VKDocuments object:

$VKDocuments = new FreedomCore\VK\API\VKDocuments($vkObject);

Now you can call methods, e.g.

$isMember = $VKDocuments->get(123456, 100); // returns 100 results
$searchForGroups = $VKDocuments->getById('123456_654321'); // gets document by ID

There are 3 API Methods presented in this Resource: 1. `get({OWNER_ID}, {COUNT optional}, {OFFSET optional})` - Returns detailed information about user or community documents 2. `getById({DOCUMENT_ID_OR_ARRAY_OF_IDS})` - Returns information about documents by their IDs 3. `getUploadServer({COMMUNITY_ID})` - Returns the server address for document upload

VKGroups Resource

*How to use:*

This Resource allows you to manage groups and work with them

Initialize New VKGroups object:

$VKGroups = new FreedomCore\VK\API\VKGroups($vkObject);

Now you can call methods, e.g.

$isMember = $VKGroups->isMember(123456, 654321, 1);
$searchForGroups = $VKGroups->search('FreedomCore');

There are 19 API Methods presented in this Resource: 1. `isMember({GROUP_ID}, {USER_ID}, {IS_EXTENDED optional})` - Returns information specifying whether a user is a member of a community 2. `getById({GROUP_ID}, {GROUP_FIELDS})` - Returns information about communities by their ID (IDs) 3. `get({USER_ID}, {IS_EXTENDED optional}, {FILTER optional}, {GROUP_FIELDS optional})` - Returns a list of the communities to which a user belongs 4. `getMembers({GROUP_ID}, {USERS_FIELDS optional})` - Returns a list of community members 5. `join({GROUP_ID}, {IS_EVENT optional})` - With this method you can join the group or public page, and also confirm your participation in an event. 6. `leave({GROUP_ID})` - With this method you can leave a group, public page, or event. 7. `search({QUERY}, {GROUP_TYPE optional})` - Searches for communities by substring. 8. `getInvites({IS_EXTENDED optional})` - Returns a list of invitations to join communities and events. 9. `getInvitedUsers({GROUP_ID}, {USERS_FIELDS optional})` - Returns invited users list of a community *(Requires Moderator Status)* 10. `banUser({GROUP_ID}, {USER_ID}, {REASON optional}, {COMMENT optional}, {BAN_ENDS optional}, {SHOW_COMMENT optional})` - Adds a user to a community blacklist *(Requires Moderator Status)* 11. `unbanUser({GROUP_ID}, {USER_ID})` - Deletes a user from a community blacklist *(Requires Moderator Status)* 12. `getBanned({GROUP_ID})` - Returns a list of users on a community blacklist *(Requires Moderator Status)* 13. `create({TITLE}, {DESCRIPTION}, {TYPE optional}, {SUB_TYPE optional})` - Creates a new community 14. `edit({GROUP_ID}, {TITLE}, {DESCRIPTION}, {SCREEN_NAME}, {ACCESS}, {WEBSITE}, {SUBJECT})` - Edits a community *(THIS METHOD INCOMPLETE)* 15. `getSettings({GROUP_ID})` - Get Group Settings 16. `getRequests({GROUP_ID}, {FIELDS optional}, {COUNT optional})` - Get Group Access Requests 17. `invite({GROUP_ID}, {USER_ID})` - Invite User To Group *(Requires Moderator Status)* 18. `removeUser({GROUP_ID}, {USER_ID})` - Remove User From Group *(Requires Moderator Status)* 19. `approveRequest({GROUP_ID}, {USER_ID})` - Approve User Request To Join Group *(Requires Moderator Status)*

VKUsers Resource

This Resource allows you to work with users and their data

*How to use:*

Initialize New VKUsers object:

$VKUsers= new FreedomCore\VK\API\VKUsers($vkObject);

Now you can call methods, e.g.

$isMember = $VKUsers->isMember(123456, 654321, 1);
$searchForGroups = $VKUsers->search('FreedomCore');

There are 6 API Methods presented in this Resource: 1. `get({USER_IDS array}, {FIELDS optional}, {CASE optional})` - Returns detailed information on users 2. `search({QUERY}, {IS_ONLINE optional}, {FIELDS optional}, {SORT optional}, {COUNT optional})` - Returns a list of users matching the search criteria 3. `isAppUser({USER_ID})` - Returns information whether a user installed the application 4. `getSubscriptions({USER_ID}, {COMBINE optional}, {FIELDS optional}, {COUNT optional})` - Returns a list of IDs of users and communities followed by the user 5. `getFollowers({USER_ID}, {OFFSET optional}, {COUNT optional}, {FIELDS optional}, {CASE optional})` - Returns a list of IDs of followers of the user in question, sorted by date added, most recent first 6. `getNearby({LATITUDE}, {LONGITUDE}, {TIMEOUT optional}, {RADIUS optional}, {FIELDS optional}, {CASE optional})` - Get Nearby Users Based On Current Latitude and Longitude


  Files folder image Files  
File Role Description
Files folder imageexamples (5 files)
Files folder imagesource (1 file, 1 directory)
Plain text file .gitattributes Data Auxiliary data
Plain text file .gitignore Data Auxiliary data
Plain text file .scrutinizer.yml Data Auxiliary data
Plain text file composer.json Data Auxiliary data
Plain text file LICENSE.md Lic. License
Plain text file README.md Doc. Documentation

  Files folder image Files  /  examples  
File Role Description
  Plain text file callback.php Example Example script
  Plain text file header.php Example Example script
  Plain text file index.php Example Example script
  Plain text file login.php Example Example script
  Plain text file logout.php Example Example script

  Files folder image Files  /  source  
File Role Description
Files folder imageAPI (6 files)
  Plain text file VKBase.php Class Class source

  Files folder image Files  /  source  /  API  
File Role Description
  Plain text file VKAccount.php Class Class source
  Plain text file VKAPI.php Class Class source
  Plain text file VKDataStorage.php Class Class source
  Plain text file VKDocuments.php Class Class source
  Plain text file VKGroups.php Class Class source
  Plain text file VKUsers.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:109
This week:1
All time:9,633
This week:571Up