spcampbell / OnlyOffice_projectList

A single page php script that queries OnlyOffice and displays projects with detail.
MIT License
0 stars 1 forks source link

Does not returns any project or error #1

Open CedricReymond opened 7 years ago

CedricReymond commented 7 years ago

Hello, I have just tried your script on my php server but it does not returns any projects nor giving me any error... I have created the token from the OO server, copied the token only to the text file and run the script. Can you help?

spcampbell commented 7 years ago

I struggled initially with the token so I would start there first. Try the following and see what you get in response. Note you have to put your url and your token the script.

`<?php

$url = 'http://**YOURONLYOFFICEURLHERE**/API/2.0/PROJECT';

$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$token = stripslashes(trim("YOURTOKENHERE"));

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization:$token", 'Accept: application/json,application/xml', 'Accept-Encoding: gzip, deflate'));

$result = curl_exec($ch); curl_close($ch);

echo $result; ?>`

CedricReymond commented 7 years ago

This script works. It returns me my project list... Don't understand why the other is not returning anything.... Thanks for your help anyway!

spcampbell commented 7 years ago

Try it with your token in the script instead of loading it in a file. Like above instead of how the script in the repository is done.

CedricReymond commented 7 years ago

not working either. This is what I get: Notice: Undefined index: count in C:\inetpub\wwwroot\Intranetv4\modules\Hd\OOprojectlist.php on line 75 Project count: Notice: Undefined index: response in C:\inetpub\wwwroot\Intranetv4\modules\Hd\OOprojectlist.php on line 93

spcampbell commented 7 years ago

I'll add some checks/validations in there this weekend and you can try again.

spcampbell commented 7 years ago

What version of OnlyOffice are you running?

CedricReymond commented 7 years ago

9.0.0 for Community and 4.4.3.6 for Document server

spcampbell commented 7 years ago

If you have a moment, can you run the following and let me know the first few lines that are returned? Mine look like this:

Array
(
    [count] => 33
    [status] => 0
    [statusCode] => 200
    [response] => Array
        (
            [0] => Array
                (

I'm curious what is yours returns with.

<?php

$url = 'http://YOURONLYOFFICEURLHERE/API/2.0/PROJECT';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$token = stripslashes(trim("YOURTOKENHERE"));

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization:$token", 'Accept: application/json,application/xml', 'Accept-Encoding: gzip, deflate'));

$result = curl_exec($ch);
curl_close($ch);

$result = curl_exec($ch);
curl_close($ch);

$r2 = json_decode($result, true);

echo"<pre>";print_r($r2);echo"</pre>";
?>
CedricReymond commented 7 years ago

I guess there is an error in your code no? This should only be run once ? $result = curl_exec($ch); curl_close($ch);

with this twice I have an errror, without it does not output anything... This is weird as your test script works fine...

CedricReymond commented 7 years ago

ok I managed to have it working. Here is what I have now:

Array
(
    [count] => 2
    [status] => 0
    [statusCode] => 200
    [response] => Array
        (
            [0] => Array
                (
                    [id] => 2
                    [title] => New Paris Office
                    [description] => Our current lease agreement for our office New Offices are needed
                    [status] => 0
                    [responsible] => Array
                        (
                            [id] => f064ad65-0338-487e-ab6c-aba0816af3c4
                            [displayName] => Benoit Francois
                            [avatarSmall] => /skins/default/images/default_user_photo_size_200-200.png
                            [profileUrl] => /products/people/profile.aspx?user=bf
                        )

                    [canEdit] => 1
                    [isPrivate] => 1
                )

            [1] => Array
                (
                    [id] => 1
                    [title] => Planification Maintenance
                    [description] => 
                    [status] => 1
                    [responsible] => Array
                        (
                            [id] => ca3d4188-7245-4d13-8a56-e6ce203a828f
                            [displayName] => Jean francois
                             [avatarSmall] => /skins/default/images/default_user_photo_size_200-200.png
                            [profileUrl] => /products/people/profile.aspx?user=jf
                        )

                    [canEdit] => 1
                    [isPrivate] => 1
                )

        )

)
CedricReymond commented 7 years ago

what should I do to have the original script working?

spcampbell commented 7 years ago

Sorry, I have not had much time to spend on this. The only way to figure out why it isn't working for you is to add some exception handling at each step, or at least some print_r in key places. I should have done the exception handling anyway. This was just a little thing for me that I decided to share. I apologize it isn't as matured as it should have been.

I'll be out of town for a few days. Hope to spend some time on it when I get back.