Giter Club home page Giter Club logo

pcloud-sdk-php's Introduction

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.

$ composer require pcloud/pcloud-php-sdk

or add the following to composer.json file

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

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/code.php and /example/auth.php.

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 return access_token and locationid.


Example

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

$access_token = "ACCESS_TOKEN";
$locationid = 1;

$pCloudApp = new pCloud\App();
$pCloudApp->setAccessToken($access_token);
$pCloudApp->setLocationId($locationid);

// Create Folder instance

$pcloudFolder = new pCloud\Folder($pCloudApp);

// Create new folder in root

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

// Create File instance

$pcloudFile = new pCloud\File($pCloudApp);

// Upload new file in created folder

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

// Get folder content

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

Creating custom requests

$access_token = "";
$locationid = 1;

$pCloudApp = new pCloud\App();
$pCloudApp->setAccessToken($access_token);
$pCloudApp->setLocationId($locationid);

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

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

pcloud-sdk-php's People

Contributors

emanuellandell avatar sich avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.