D
D
Dark_Dante2015-07-13 15:00:10
CodeIgniter
Dark_Dante, 2015-07-13 15:00:10

How to connect Yandex Disk for a website?

Hello.
There is a need to store some files somewhere. We decided to use Yandex disk for this business I
registered the application on Yandex, received an ID, Password, Callback URL
Downloaded the phar-archive, connected
Everything as here
https://github.com/nixsolutions/yandex-php-library
I do it as in the example here
https ://github.com/nixsolutions/yandex-php-library...
I have a project on CodeIgniter, the code is like this

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
use Yandex\OAuth\OAuthClient;
use Yandex\Disk\DiskClient;
class Test extends CI_Controller {
    public function __construct(){
    parent::__construct();
    }
    public function index(){
        //$this->load->helper('yadisk');
        require_once 'phar://yandex-php-library_0.4.0.phar/vendor/autoload.php';
        $post=$this->input->post();
        if(!empty($post)){
            
           $file = array(
                            'name' => $_FILES['image']['name'],
                            'size' => $_FILES['image']['size'],
                            'path' => $_FILES['image']['tmp_name']
                        );
           //var_dump($_FILES); exit;
             $client = $client = new OAuthClient('Тут_мой_ID');
             $client->setAccessToken('тут_пароль?');
             $token=$client->getAccessToken();
            $diskClient = new DiskClient($token );
             $diskClient->setServiceScheme(DiskClient::HTTPS_SCHEME);
            header('Content-type: application/json');
            $result = $diskClient->diskSpaceInfo();
            $result['login'] = $diskClient->getLogin();
            echo json_encode($result);
            
        }else {
            echo "<form action='/test/' method='post' enctype='multipart/form-data'>
                <input type='file' name='image'/>
                <input type='submit' value='Ok' name='submit'/>    
            </form>";
        }
    }
}

Throws 401 error - unregistered I
suspect that I'm passing the ID or password somewhere in the wrong place, but the token is successfully generated
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Tanchik194, 2015-07-23
@Tanchik194

$client->setAccessToken('password here?');

There should be a token here that you receive after authorization, because This method is for authorized user only.
See this example .
Read the documentation here

D
Dmitry, 2015-07-13
@2fox

$client = $client = new OAuthClient('My_ID is here');
$client->setAccessToken('password here?');

incorrectly
following your links, I see that the settings are stored in https://github.com/nixsolutions/yandex-php-library...

D
Dmitry, 2015-07-29
@AaAAxzz

I think you'd better try to use another library https://github.com/jack-theripper/Mackey when you get the token, check "REST API Disk" and then something like this
$disk = new Mackey\Yandex\Disk(' token');
var_dum($disk->getContents());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question