Skip to content
This repository has been archived by the owner on Feb 12, 2019. It is now read-only.

It can be use? i download and blank show! #2

Closed
vulieumang opened this issue Jun 17, 2016 · 10 comments
Closed

It can be use? i download and blank show! #2

vulieumang opened this issue Jun 17, 2016 · 10 comments

Comments

@vulieumang
Copy link

It can be use? i download and blank show!
Please help me setup and use it!

@Alorel
Copy link
Owner

Alorel commented Jun 17, 2016

Did you follow the installation instructions? I just tried installing it as per instructions and it worked as expected.

Simply install Composer, navigate to the directory your project is in, run

composer require alorel/dropbox-v2-php

or, if you already have a composer.json file in your project, add this package to your requirements:

{
    "require": {
        "alorel/dropbox-v2-php": "^0.3"
    }
}

Make sure your installation meets the requirements, i.e. PHP 5.6 and newer. In the end your directory should look something like this and one of your php files would look something like this:

<?php

    use Alorel\Dropbox\Operation\Files\ListFolder\ListFolder;
    use GuzzleHttp\Exception\ClientException;

    require_once 'vendor/autoload.php';

    $apikey = 'INPUT_YOUR_ACCESS_TOKEN_HERE';
    $list = new ListFolder(false, $apikey);

    try {
        var_dump(
            json_decode(
                $list->raw('/path-to-folder')->getBody()->getContents(),
                true
            )
        );
    } catch (ClientException $e) {
        echo $e->getMessage();
    }

@vulieumang
Copy link
Author

Thank man
I not found the liblary alorel/dropbox-v2-php and i think maybe it not done.
Thank you a lot for only 1 API v2 dropbox on github.

Can i ask a question, should do i use v1 or v2 dropbox api for better performance, i only need upload via API of dropbox but so hard to find a simple example to upload dropbox via api. example almost by native code or library not via API.

Thank again for beautiful code. :)

@Alorel
Copy link
Owner

Alorel commented Jun 17, 2016

It's just the way Composer works. 😉 This SDK is as close as you can get to raw API calls - all it does is wrap HTTP requests in PHP code. Have a look at the general instructions, upload and UploadSession examples and their documentation here and here. The arguments these methods receive map directly to the ones the Dropbox API expects.

As for v1 vs v2, definitely go for v2 - it's newer and more actively developed, Dropbox want you to use v2, too.

Let me know if you have any more questions - if not, I'll be closing the issue.

@Alorel Alorel closed this as completed Jun 17, 2016
@vulieumang
Copy link
Author

Can you tell me how to use /save_url.

i use https://github.com/Alorel/dropbox-v2-php/blob/master/examples/Raw/Files/SaveURL.md
but have this error

image

@vulieumang
Copy link
Author

vulieumang commented Jun 17, 2016

<?php

    use Alorel\Dropbox\Operation\Files\SaveUrl\CheckJobStatus;
    use Alorel\Dropbox\Operation\Files\SaveUrl\SaveURL;
    use Alorel\Dropbox\Operation\Files\ListFolder\ListFolder;
    use GuzzleHttp\Exception\ClientException;



    $saveURL = new SaveURL();
    $resp = json_decode($saveURL->raw('/google.html', 'https://www.google.com')->getBody()->getContents(), true);

    if (isset($resp['async_job_id'])) {
        $check = new CheckJobStatus();

        do {
            sleep(3); //Wait a bit
            $r = json_decode($check->raw($resp['async_job_id'])->getBody()->getContents(), true);
        } while (isset($r['.tag']) && $r['.tag'] == 'in_progress');

        //You're done - URL saved
        } else {
        //You're done - URL saved
    }   

@Alorel
Copy link
Owner

Alorel commented Jun 17, 2016

Please follow the installation instructions on the Readme and look at the examples.

This package requires knowledge of Composer and namespacing in PHP. Please look at how both of those are used before raising any more questions that aren't tied to this package.

This package will not work if you just clone the source and try to use it.

@vulieumang
Copy link
Author

vulieumang commented Jun 17, 2016

Thank Alorel for the answer :)
i had success run your example
image
But some error when i use some namespace

<?php

    use Alorel\Dropbox\Operation\Files\ListFolder\ListFolder;  //is okay
    use GuzzleHttp\Exception\ClientException;//is okay

    use Alorel\Dropbox\Operation\Files\SaveUrl\CheckJobStatus;//is okay
    use Alorel\Dropbox\Operation\Files\SaveUrl\SaveURL; //return not found

Hope i don't disturb you.
Can you help me once more time, please!

When i use

<?php

    use Alorel\Dropbox\Operation\Files\ListFolder\ListFolder;  //is okay
    use GuzzleHttp\Exception\ClientException;//is okay  
    use Alorel\Dropbox\Operation\Files\SaveUrl\CheckJobStatus;//is okay

it return okay but when

<?php

    use Alorel\Dropbox\Operation\Files\ListFolder\ListFolder;  //is okay
    use GuzzleHttp\Exception\ClientException;//is okay

    use Alorel\Dropbox\Operation\Files\SaveUrl\CheckJobStatus;//is okay
    use Alorel\Dropbox\Operation\Files\SaveUrl\SaveURL; //return not found

have error
Fatal error: Class 'Alorel\Dropbox\Operation\Files\SaveUrl\SaveURL' not found in D:\xampp\htdocs\dropbox-v2-php-master\index1.php on line 11

@Alorel
Copy link
Owner

Alorel commented Jun 17, 2016

You'll find your answer in Composer's getting started documents. Everything works, otherwise it wouldn't have passed the unit tests on Travis-CI.

<?php

    use Alorel\Dropbox\Operation\Files\SaveUrl\CheckJobStatus;
    use Alorel\Dropbox\Operation\Files\SaveUrl\SaveURL;

   ################################
   # INCLUDE THE AUTOLOADER BELOW #
   ################################
    require_once 'vendor/autoload.php'; 
   ##################
   # IT'S IMPORTANT #
   ##################

    SaveURL::setDefaultToken('Your token');
    SaveURL::setDefaultAsync(false);

    $saveURL = new SaveURL();
    $resp = json_decode($saveURL->raw('/google.html', 'https://www.google.com')->getBody()->getContents(), true);

    if (isset($resp['async_job_id'])) {
        $check = new CheckJobStatus();

        do {
            echo 'Not saved yet - waiting for 3 seconds before checking for the job status' . PHP_EOL;
            sleep(3); //Wait a bit
            $r = json_decode($check->raw($resp['async_job_id'])->getBody()->getContents(), true);
        } while (isset($r['.tag']) && $r['.tag'] == 'in_progress');

        echo 'URL saved';
    } else {
        echo 'URL saved';
    }

@Alorel Alorel reopened this Jun 17, 2016
@Alorel Alorel closed this as completed Jun 17, 2016
@vulieumang
Copy link
Author

vulieumang commented Jun 17, 2016

Thank for your kindness.
I had use composer before.
image
But still error, may be i wrong somewhere.

Thank again for your help and great lib and so sorry about my disturb :(

@Alorel
Copy link
Owner

Alorel commented Jun 17, 2016

Composer on its own won't do anything - you need to include the autoloaded as I did in the example above - that way simply referencing a class by name will be enough to automatically load the file containing that class.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants