Skip to content

emanuellandell/pcloud-sdk-php

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pCloud SDK for PHP

A PHP library to access pCloud API


Table of Contents


System requirements


Get started

Register your application

In order to use this SDK, you have to register your application in My applications.


Install the SDK

Using Composer

Install Composer. Add the following to composer.json file

"require": {
  "pcloud/pcloud-php-sdk": "1.*"
}

Manually

Copy lib/ folder and include lib/pCloud/autoload.php in your code


Initializing the SDK

The SDK uses an OAuth 2.0 access token to authorize requests to the pCloud API. You can obtain a token using the SDK's authorization flow. To allow the SDK to do that, find App Key, App secret and Redirect URIs in your application configuration page and add them to /example/app.info file.

{
  "appKey": "App key",
  "appSecret": "App secret",
  "redirect_uri": "Redirect URI"
}

Note that redirect_uri is optional.

Run /example/code.php to get an authorization code and use this code in /example/auth.php. This will generate /lib/pCloud/app.cred file with your credentials.


Example

// Include autoload.php and set the credential file path

require_once("../lib/pcloud/autoload.php");
pCloud\Config::$credentialPath = "../lib/pCloud/app.cred";

// Create Folder instance

$pcloudFolder = new pCloud\Folder();

// Create new folder in root

$folderId = $pcloudFolder->create("New folder");

// Create File instance

$pcloudFile = new pCloud\File();

// Upload new file in created folder

$fileMetadata = $pcloudFile->upload("./sample.png", $folderId);

// Get folder content

$folderContent = $pcloudFolder->getContent($folderId);

Creating custom requests

$method = "userinfo";
$params = array();

$request = new pCloud\Request();
$response = $request->get($method, $params); // the second argument is optional

Packages

No packages published

Languages

  • PHP 100.0%