mesilov / bitrix24-php-sdk

A powerful PHP library for the Bitrix24 REST API
MIT License
409 stars 161 forks source link

How to start using the library #28

Closed damianoporta closed 8 years ago

damianoporta commented 8 years ago

Hello, I have downloaded your library but i do not understand what data should i pass to:

$obB24App->setDomain($arParams['DOMAIN']); // this should be {domain}.bitrix24.com right ?
$obB24App->setMemberId($arParams['MEMBER_ID']);
$obB24App->setAccessToken($arParams['AUTH_ID']);
$obB24App->setRefreshToken($arParams['REFRESH_ID']);

Could you give me more information? Thank you!

yugene commented 8 years ago

Hello!

You cah find some additional information here: https://dev.1c-bitrix.ru/community/blogs/b24_marketplace/marketplace-bitriks24-how-to-make-oauth-authentication-for-desktop-app.php?commentId=70248.

Or in English: https://training.bitrix24.com/rest_help/oauth/examles.php

damianoporta commented 8 years ago

@yugene thank you!

mborodov commented 8 years ago

@yugene You need get code first

example my code


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

// получаем code и member_id если нету
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();
}

// создадим объект логгера
$log = new \Monolog\Logger('bitrix24');
$log->pushHandler(new \Monolog\Handler\StreamHandler('./bitrix24.log', \Monolog\Logger::INFO));

// создаем битрикс24 объекты
$obB24App = new \Bitrix24\Bitrix24(false, $log);
$obB24App->setApplicationScope(['task', 'entity']);
$obB24App->setApplicationId(APPLICATION_ID);
$obB24App->setApplicationSecret(APPLICATION_SECRET);

// данные пользователя
$obB24App->setDomain(DOMAIN);
$obB24App->setRedirectUri(REDIRECT_URL);
$obB24App->setMemberId($_GET['member_id']);
$obB24App->setAccessToken($obB24App->getFirstAccessToken($_GET['code'])['access_token']);