M
M
Mesuti2021-07-13 20:14:43
PHP
Mesuti, 2021-07-13 20:14:43

How to connect to dadata in php?

Hey!
How to connect to api dadata in php?

I copy files from Github to the root of the folder.
60edc9b616c4d114163513.png

In the working file, I specify everything as in the dadata index.php instruction :


<?php
$token = "7c64bad5478644ec171f7a01e6146da958076";
$secret = "83f1a6f5bc781d4d6dd778e1cfe4529a7ca86";
$dadata = new \Dadata\DadataClient($token, $secret);
$result = $dadata->findById("fns_unit", "5257");
echo $result;


When accessing the index.php file, a server error 500 occurs

How to connect and issue data from dadata correctly?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
ThunderCat, 2021-07-13
@Mesuti

read what error 500 is
Do what is recommended in such cases
Correct
Composer, of course, you did not use ...
I'm sure that the backwardness of the developers has nothing to do with it, but someone else is lagging behind the progress.

M
Mesuti, 2021-07-13
@Mesuti

Thanks to everyone who answered and to the developers, you can install Composer and other fashionable things yourself.
Who's Doing Business -
Retrieving data using PHP, a ready-made example

<?php

$data = [
    'query' => 'москва'
];
$options = [
    'http' => [
        'method' => 'POST',
        'header' => [
            'Content-Type: application/json',
            'Accept: application/json',
            'Authorization: Token 7c64bad5478644ec171f7a01e6146da958076'
        ],
        'content' => json_encode($data)
    ]
];
$builder = stream_context_create($options);
$document = file_get_contents('https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/fns_unit', false, $builder);
$output = json_decode($document);
var_dump($output);

N
nalgeon, 2021-08-05
@nalgeon

If you don’t know how or don’t want to work with composer: an example of calling “Dadata” from PHP with one file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question