freedomcore / vk-api
FreedomCore VK API Library
Requires
- php: >=5.6
- ext-curl: *
- ext-pdo: *
This package is auto-updated.
Last update: 2024-10-24 23:32:34 UTC
README
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
- Create New Object
a. To work with Library before authorization completed
b. To work with Library after authorization completed$vkObject = new FreedomCore\VK\VKBase('{APPLICATION_ID}', '{API_SECRET}');
$vkObject = new FreedomCore\VK\VKBase('{APPLICATION_ID}', '{API_SECRET}', '{ACCESS_TOKEN}');
- How to authorize user
a. Generate Authorization Link
b. Get Access Token By Using Key From Callback$vkObject->getAuthorizationURL('{SCOPE}', '{CALLBACK_URL}');
c. Check, if user authorized$vkObject->getAccessToken('{CODE}');
$vkObject->isAuthorized(); // returns true | false
- Now you can work with API
Resources
VKBase Resource
This is the main Library resource
There are 4 API Methods presented in this Resource:
setAPIVersion({API_VERSION})
- Set API Version Provided By UsergetAuthorizationURL({SCOPE}, {CALLBACK_URL}, {RESPONSE_TYPE}, {TEST_MODE})
- Returns Authorization Link With Passed ParametersgetAccessToken({CODE}, {CALLBACK_URL})
- Returns Access Token From Authorization LinkisAuthorized()
- 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:
getCounters({USER_FIELDS optional)
- Fetches all counters which are greater than zero (messages, videos, friends, etc)setNameInMenu({USER_ID}, {APPLICATION_NAME}
- Creates Sidebar Link to application, if user allowed itsetOnline()
- Sets status to Online for 15 minutessetOffline()
- Sets status to OfflinegetActiveOffers({OFFSET optional}, {COUNT optional})
- Returns a list of active ads (offers)getAppPermissions()
- Gets settings of the current user in this application
VKDataStorage Resource
Missing Description
There are 3 API Methods presented in this Resource:
get({KEY}, {KEYS}, {USER_ID}, {IS_GLOBAL})
- Returns a value of variable with the name set by key parameterset({KEY}, {VALUE}, {USER_ID}, {IS_GLOBAL})
- Saves a value of variable with the name set by key parametergetKeys({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:
get({OWNER_ID}, {COUNT optional}, {OFFSET optional})
- Returns detailed information about user or community documentsgetById({DOCUMENT_ID_OR_ARRAY_OF_IDS})
- Returns information about documents by their IDsgetUploadServer({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:
isMember({GROUP_ID}, {USER_ID}, {IS_EXTENDED optional})
- Returns information specifying whether a user is a member of a communitygetById({GROUP_ID}, {GROUP_FIELDS})
- Returns information about communities by their ID (IDs)get({USER_ID}, {IS_EXTENDED optional}, {FILTER optional}, {GROUP_FIELDS optional})
- Returns a list of the communities to which a user belongsgetMembers({GROUP_ID}, {USERS_FIELDS optional})
- Returns a list of community membersjoin({GROUP_ID}, {IS_EVENT optional})
- With this method you can join the group or public page, and also confirm your participation in an event.leave({GROUP_ID})
- With this method you can leave a group, public page, or event.search({QUERY}, {GROUP_TYPE optional})
- Searches for communities by substring.getInvites({IS_EXTENDED optional})
- Returns a list of invitations to join communities and events.getInvitedUsers({GROUP_ID}, {USERS_FIELDS optional})
- Returns invited users list of a community (Requires Moderator Status)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)unbanUser({GROUP_ID}, {USER_ID})
- Deletes a user from a community blacklist (Requires Moderator Status)getBanned({GROUP_ID})
- Returns a list of users on a community blacklist (Requires Moderator Status)create({TITLE}, {DESCRIPTION}, {TYPE optional}, {SUB_TYPE optional})
- Creates a new communityedit({GROUP_ID}, {TITLE}, {DESCRIPTION}, {SCREEN_NAME}, {ACCESS}, {WEBSITE}, {SUBJECT})
- Edits a community (THIS METHOD INCOMPLETE)getSettings({GROUP_ID})
- Get Group SettingsgetRequests({GROUP_ID}, {FIELDS optional}, {COUNT optional})
- Get Group Access Requestsinvite({GROUP_ID}, {USER_ID})
- Invite User To Group (Requires Moderator Status)removeUser({GROUP_ID}, {USER_ID})
- Remove User From Group (Requires Moderator Status)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:
get({USER_IDS array}, {FIELDS optional}, {CASE optional})
- Returns detailed information on userssearch({QUERY}, {IS_ONLINE optional}, {FIELDS optional}, {SORT optional}, {COUNT optional})
- Returns a list of users matching the search criteriaisAppUser({USER_ID})
- Returns information whether a user installed the applicationgetSubscriptions({USER_ID}, {COMBINE optional}, {FIELDS optional}, {COUNT optional})
- Returns a list of IDs of users and communities followed by the usergetFollowers({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 firstgetNearby({LATITUDE}, {LONGITUDE}, {TIMEOUT optional}, {RADIUS optional}, {FIELDS optional}, {CASE optional})
- Get Nearby Users Based On Current Latitude and Longitude