2019-02-07 19:23:14 -08:00
< ? php
/**
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* This file is licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License. A copy of
* the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
2019-02-09 15:38:20 -08:00
* For more information about creating a WorkDocs application see the WorkDocs Developer Guide at
* https://docs.aws.amazon.com/workdocs/latest/developerguide/wd-auth-user.html
2019-02-07 19:23:14 -08:00
*
*
*/
// snippet-start:[workdocs.php.list_folders.complete]
// snippet-start:[workdocs.php.list_folders.import]
require 'vendor/autoload.php' ;
use Aws\Exception\AwsException ;
2019-02-09 15:38:20 -08:00
use Aws\WorkDocs\WorkDocsClient ;
2019-02-07 19:23:14 -08:00
// snippet-end:[workdocs.php.list_folders.import]
/**
* List Folders currently in your Amazon WorkDocs.
*
* This code expects that you have AWS credentials set up per:
* https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html
*/
// Create a workdocs Client
// snippet-start:[workdocs.php.list_folders.main]
$client = new Aws\WorkDocs\WorkDocsClient ([
'profile' => 'default' ,
'version' => '2016-05-01' ,
'region' => 'us-east-2'
]);
2019-02-09 15:38:20 -08:00
$auth_token_file_path = 'token.txt' ;
2019-02-07 19:23:14 -08:00
try {
2019-02-09 15:38:20 -08:00
$file = fopen ( $auth_token_file , 'r' ) or die ( " Unable to open file! " );
$auth_token = fread ( $auth_token_file , filesize ( $auth_token_file ));
fclose ( $auth_token_file );
2019-02-09 16:01:18 -08:00
$result = $client -> $result = $client -> describeRootFolders ([
2019-02-09 15:38:20 -08:00
'AuthenticationToken' => $auth_token
]);
2019-02-07 19:23:14 -08:00
foreach ( $result [ 'Folders' ] as $folder ){
2019-02-09 15:38:20 -08:00
print ( " <p>Folder - <b> " . $folder [ 'Name' ] . " </b> , id - <b> " . $folder [ 'Id' ]);
print ( " </b> , Parent Folder - " . $folder [ 'ParentFolderId' ] . " </p> " );
2019-02-07 19:23:14 -08:00
}
var_dump ( $result );
} catch ( AwsException $e ) {
// output error message if fails
2019-02-09 15:40:51 -08:00
echo $e -> getMessage () . " \n " ;
2019-02-07 19:23:14 -08:00
}
// snippet-end:[workdocs.php.list_folders.main]
// snippet-end:[workdocs.php.list_folders.complete]
// snippet-comment:[These are tags for the AWS doc team's sample catalog. Do not remove.]
// snippet-sourcedescription:[GetFolders.php demonstrates how to list folders currently in your Amazon WorkDocs.]
// snippet-keyword:[PHP]
// snippet-keyword:[AWS SDK for PHP v3]
// snippet-keyword:[Code Sample]
2019-02-09 16:01:18 -08:00
// snippet-keyword:[describeRootFolders]
2019-02-07 19:23:14 -08:00
// snippet-keyword:[Amazon WorkDocs]
// snippet-service:[workdocs]
// snippet-sourcetype:[full-example]
2019-02-09 15:38:20 -08:00
// snippet-sourcedate:[2019-02-09]
2019-02-07 19:23:14 -08:00
// snippet-sourceauthor:[jschwarzwalder (AWS)]