Created
March 3, 2016 17:41
-
-
Save mborodov/294742a37557b686b22a to your computer and use it in GitHub Desktop.
Bitrix application 3 type with authorization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// for log errors | |
error_reporting(E_ALL); | |
ini_set('display_errors', 1); | |
// autoload classes | |
include_once __DIR__.'/vendor/autoload.php'; | |
// define variables | |
const APPLICATION_ID = 'local.56d4c44e94a076.41291969'; | |
const APPLICATION_SECRET = '891fb1cf1312fae25b48eccebe65c846'; | |
const PROTOCOL = 'https'; | |
const DOMAIN = 'supertest.bitrix24.ru'; | |
const REDIRECT_URL = 'http://mborodov.it-master.su'; | |
const PATH = 'https'; | |
// Get code and member_id if not exist | |
if(empty($_GET['code']) || empty($_GET['member_id'])){ | |
$params = array( | |
"response_type" => "code", | |
"client_id" => APPLICATION_ID, | |
"redirect_uri" => REDIRECT_URL, | |
); | |
$path = "/oauth/authorize/"; | |
Header("HTTP 302 Found"); | |
Header("Location: ".PATH.'://'.DOMAIN.$path."?".http_build_query($params)); | |
die(); | |
} | |
// create log | |
$log = new \Monolog\Logger('bitrix24'); | |
$log->pushHandler(new \Monolog\Handler\StreamHandler('./bitrix24.log', \Monolog\Logger::DEBUG)); | |
//create bitrix24 objects | |
$obB24App = new \Bitrix24\Bitrix24(false, $log); | |
$obB24App->setApplicationScope(['task']); | |
$obB24App->setApplicationId(APPLICATION_ID); | |
$obB24App->setApplicationSecret(APPLICATION_SECRET); | |
// set user-specific settings | |
$obB24App->setDomain(DOMAIN); | |
$obB24App->setRedirectUri(REDIRECT_URL); | |
$obB24App->setMemberId($_GET['member_id']); | |
$obB24App->setAccessToken($obB24App->getFirstAccessToken($_GET['code'])['access_token']); | |
// get information about all tasks | |
$tasks = new \Bitrix24\Task\Items($obB24App); | |
var_dump($tasks->getList()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment