Giter Club home page Giter Club logo

onedrive-php-sdk's Introduction

OneDrive SDK for PHP

Latest Stable Version Total Downloads Build Status Code Coverage StyleCI

The OneDrive SDK for PHP is an open source library that allows PHP applications to interact programmatically with the OneDrive REST API.

It supports operations such as creating, reading, updating, deleting (CRUD) files and folders, as well as moving or copying them to other folders.

Requirements

Using the OneDrive SDK for PHP requires the following:

  • PHP 7.3 or newer ;
  • Composer or a manual install of the dependencies mentioned in composer.json.

Testing

Running its functional tests also require:

  • A OneDrive web application configured with http://localhost:7777/ as its redirect URI ;
  • A WebDriver server, for example the Selenium Server (Grid) ;
  • A Chrome browser & ChromeDriver, and they must be usable by the WebDriver server.

Installation

The recommended way to install OneDrive SDK for PHP is to install it using Composer:

composer require krizalys/onedrive-php-sdk

If you are not already using Composer in your PHP project, refer to the Composer documentation to learn how to set it up.

Quick start

To use the OneDrive SDK for PHP, you require a web application exposing a URL initiating the authorization flow. Typically, this URL, referred to as your web application's Redirect URI, is a PHP script requesting an authorization token. This token is required whenever your web application interacts with your users' OneDrive contents and may be reused across multiple calls. An example of such a web application is our functional test suite.

You also require a OneDrive application. To register such an application, first sign in to Microsoft Azure, then visit App registrations and add a registration for your application. While registering your application, you need to set its Redirect URI, explained above. We currently only support Web redirect URIs.

Once created, your application is assigned an Application (client) ID, referred to as its Client ID. In Certificate & secrets, you also need to add at least one Client secret. Warning: Client Secrets are similar to passwords or private keys by allowing an application to identify as yours: therefore, Client Secrets should be kept private.

Once you have a Redirect URI, a Client ID, and a Client Secret, your web application can start using the OneDrive SDK for PHP in three steps.

Step 1: create your configuration

As you may need them from several scripts, we recommend saving your Client ID, Client secret and Redirect URI in a configuration file, for example:

config.php

<?php

return [
    /**
     * Your OneDrive client ID.
     */
    'ONEDRIVE_CLIENT_ID' => '<YOUR_CLIENT_ID>',

    /**
     * Your OneDrive client secret.
     */
    'ONEDRIVE_CLIENT_SECRET' => '<YOUR_CLIENT_SECRET>',

    /**
     * Your OneDrive redirect URI.
     */
    'ONEDRIVE_REDIRECT_URI' => 'http://your.domain.com/redirect.php',
];

Step 2: direct your users to the sign in page

This script is responsible for, given a set of privileges, fetching a log in URL from the OneDrive API. It needs to direct users to this URL to initiate their log in and privilege granting process. The script should look like this:

index.php

<?php

($config = include __DIR__ . '/config.php') or die('Configuration file not found');
require_once __DIR__ . '/vendor/autoload.php';

use Krizalys\Onedrive\Onedrive;

// Instantiates a OneDrive client bound to your OneDrive application.
$client = Onedrive::client($config['ONEDRIVE_CLIENT_ID']);

// Gets a log in URL with sufficient privileges from the OneDrive API.
$url = $client->getLogInUrl([
    'files.read',
    'files.read.all',
    'files.readwrite',
    'files.readwrite.all',
    'offline_access',
], $config['ONEDRIVE_REDIRECT_URI']);

session_start();

// Persist the OneDrive client' state for next API requests.
$_SESSION['onedrive.client.state'] = $client->getState();

// Redirect the user to the log in URL.
header('HTTP/1.1 302 Found', true, 302);
header("Location: $url");

Step 3: get an OAuth access token

After the users follow this URL, they are required to sign into their Microsoft account, and they are asked whether they agree to allow your web application to access their OneDrive account.

If they do, they are redirected to your Redirect URI and a code is passed in the query string of this URL. The script at this URL essentially:

  1. Instantiates a Client from your configuration and the state from previous instantiations ;
  2. Obtains an OAuth access token using Client::obtainAccessToken(), passing it the code received ;
  3. Starts interacting with the files and folders stored in their OneDrive account, or delegates this responsibility to other scripts which in turn may spawn other Client instances from the same state.

It typically looks like this (replace /path/to by the appropriate values):

redirect.php

<?php

($config = include __DIR__ . '/config.php') or die('Configuration file not found');
require_once __DIR__ . '/vendor/autoload.php';

use Krizalys\Onedrive\Onedrive;

// If we don't have a code in the query string (meaning that the user did not
// log in successfully or did not grant privileges requested), we cannot proceed
// in obtaining an access token.
if (!array_key_exists('code', $_GET)) {
    throw new \Exception('code undefined in $_GET');
}

session_start();

// Attempt to load the OneDrive client' state persisted from the previous
// request.
if (!array_key_exists('onedrive.client.state', $_SESSION)) {
    throw new \Exception('onedrive.client.state undefined in $_SESSION');
}

$client = Onedrive::client(
    $config['ONEDRIVE_CLIENT_ID'],
    [
        // Restore the previous state while instantiating this client to proceed
        // in obtaining an access token.
        'state' => $_SESSION['onedrive.client.state'],
    ]
);

// Obtain the token using the code received by the OneDrive API.
$client->obtainAccessToken($config['ONEDRIVE_CLIENT_SECRET'], $_GET['code']);

// Persist the OneDrive client' state for next API requests.
$_SESSION['onedrive.client.state'] = $client->getState();

// Past this point, you can start using file/folder functions from the SDK, eg:
$file = $client->getRoot()->upload('hello.txt', 'Hello World!');
echo $file->download();
// => Hello World!

$file->delete();

For details about classes and methods available, see the API reference or the project page on Krizalys.

Versioning

OneDrive SDK for PHP adheres to Semantic Versioning: we are committed not to introduce breaking changes to the public API without incrementing the major version number. We also try to document such changes in the changelog.

However, we only consider symbols marked with the @api annotation to be part of the public API and subject to Semantic Versioning requirements. Other symbols are considered internal and may change or get removed without a major version increment. To avoid breaking changes, use only symbols from the public API in your code.

Testing

To run the functional test suite:

  1. Set your application configuration at test/functional/config.php ;

  2. Run your WebDriver server, for example:

    java -jar selenium-server-4.8.3.jar standalone
  3. Run the functional test suite (it assumes that WebDriver listening on port 4444):

    vendor/bin/paratest --functional --configuration test --testsuite 'Functional tests' --bootstrap test/functional/bootstrap.php
  4. Repeat step 3 as needed.

License

The OneDrive SDK for PHP is licensed under the 3-Clause BSD License.

Credits

The OneDrive SDK for PHP is developed and maintained by Christophe Vidal.

onedrive-php-sdk's People

Contributors

ardabeyazoglu avatar christophe-ddproperty avatar davidanderson684 avatar faradey avatar gotham25 avatar jacobembree avatar krizalys avatar muntianrazvan avatar ondram avatar paulorwd avatar smaknsk avatar solepixel avatar uuf6429 avatar wimwinterberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

onedrive-php-sdk's Issues

Automatically Refresh Token?

Thanks for sharing this library! My only previous experience with an OAuth library is with thephpleague/oauth2-client and whenever the token had expired, a new one was generated with the Refresh Token automatically.

I have noticed that once you authorize the application, the token is only good for the first expiration period. After it expires, it makes no attempt to use the RefreshToken to generate a new OAuth token.

Is there a built in method for handling an OAuth token refresh in your SDK? If not, do you have a recommended way of handling getting a new Token? I'd be happy to look into contributing something that handles this if one does not already exist.

Expected Behavior:

  1. Authorize Application
  2. Make an API call with OAuth Token
  3. If Token has expired, automatically retrieve a new Token with RefreshToken before continuing with API call.
  4. Complete API call successfully with new Token.

Actual Behavior:

  1. Authorize Application
  2. Make an API call with OAuth Token
  3. If Token has expired, API call fails since it does not renew the Token.
  4. API call does not complete successfully using expired Token.

Thanks, please let me know if I can help any further!

Live sdk api has deprecated since a year and will not continue after November 1, 2018

As per migration guide on https://docs.microsoft.com/en-us/onedrive/developer/rest-api/concepts/migrating-from-live-sdk , The live sdk api has deprecated since a year and will not continue after November 1, 2018. This paragraph is as below:

Live SDK and Live Connect APIs have been marked as deprecated for over a year. As announced on the Office Developer blog, these APIs are now end of life and will no longer
be available after November 1, 2018.

You can see it on relevant screenshot: https://imgur.com/a/Oyj1G

So after November 1, 2018, this library will not work due to expiry of live sdk.

Also, There are onedrive for business is not with live sdk api.

There is migration guide on https://docs.microsoft.com/en-us/onedrive/developer/rest-api/concepts/migrating-from-live-sdk

From https://docs.microsoft.com/en-us/onedrive/developer/rest-api/:

OneDrive REST API is a portion of the Microsoft Graph API which allows your app to connect to content stored in OneDrive and SharePoint. The REST API is shared between OneDrive, OneDrive for Business, SharePoint document libraries, and Office Groups, to allow your app the flexibility to read and store content in any of these locations with the same code.

May i know have you any plan to migrate Live sdk to Microsoft Graph rest api?

Thank you very very much in advance. I hall wait for your reply.

Difference between Organizational/ business Account and Personal Account

Hi Krizalys
Thanks for this awesome SDK.

I was trying to use this SDK but am facing 2 weird issues:

  1. I have a personal account, using which I am able to check the folder shared with me. But when I use this API, and list out the FetchRoot - I am not able to see the shared folder. Please note that the URL of the shared folder is not https://onedrive.live.com . So my question is, how to use this SDK for OneDrive for Business.
  2. I uploaded a file to my onedrive manually. Now, when I am trying to fetch that file using FetchFile (and giving correct ID), the SDK provides some details of the file, but the content part of the result is empty.

Can you please help us out.

Multipart upload support

Does this library support multipart uploads? I need to be able to break up uploading across multiple page loads for large files. OneDrive supports this as seen here: https://dev.onedrive.com/items/upload_post.htm

I need this because my app runs on users' shared hosting accounts which tend to have unmodifiable maximum execution time limits and slow speeds so I need to be able to break it up. I do this with Amazon S3, Dropbox, Google Drive, Rackspace, etc within my app but I'd like to use this library to add OneDrive support but this is critical for my use case.

Lack of Feature: Share and Invite

Add share permission to others:
https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_invite?view=odsp-graph-online

Create share links:
https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_createlink?view=odsp-graph-online

Add a share folder to your onedrive:
https://docs.microsoft.com/en-us/onedrive/developer/rest-api/concepts/using-sharing-links?view=odsp-graph-online#add-a-shared-folder-to-the-users-drive

btw, it is useful in China to add share permission without invition in Account A and add it to onedrive root to Account B. Chinese can use onedrive client and mobile app but cannot visit onedrive.live.com

Share Link

Not been able to create a share link for an item. Please help me with ths

Upload Support - "Create file"

Great SDK by the way. Really helped me to get started.

I wondered if there was any more information about uploading files from local machine. I see we have "Creating a OneDrive file" with a content field but I wondered if i had a zip, or image what would the steps be (if it can handle this method)?

Reason: curl_exec() failed: SSL read: errno -5961

Notice: Undefined property: stdClass::$access_token in /var/www/html/onedrive-php-sdk/src/Krizalys/Onedrive/Client.php on line 544

I cannot run the example with a libcurl error about ssl. What should i do?

How to obtain a users ID or UserPrincipleName OR How to upload file into 3rd Party Folder

Hi there. Is there a way to get the id/UPN for a user in this library so I can push files into 3rd party folders?

There's a method here that points towards it, but I can't see where I can get the ID : getDriveByUser($idOrUserPrincipalName)

A 3rd party authenticates, but how to put stuff in their folders?

Note - client ID is not the $idOrUserPrincipleName. It's the app ID.

[Question] What OneDrive URI to use with the Office protocol?

I'm posting this here cause after 2 days I'm unable to find any info, so I'm getting desperate, I apologize beforehand.

When fetching a .docx file, $onedrive returns an object containing properties, like this:

stdClass Object
(
    [id] => file.A1B2C3D4.A1B2C3D4!100
    ...
    [name] => Test document.docx
    ...
    [upload_location] => https://apis.live.net/v5.0/file.A1B2C3D4.A1B2C3D4!100/content/
    ...
    [source] => https://4k3emw-dm2306.files.1drv.com/som-random-string/Test%20document.docx?psid=1
    [link] => https://onedrive.live.com/redir.aspx?cid=A1B2C3D4&page=view&resid=A1B2C3D4!112&parId=D7C6A1C2!101
    ...
)

Which one of those should I use to build the protocol ms-word:ofe%7Cu%7Chttps:// <URL>

Thanks in advance

Need to be updated to Microsoft Graph API before Nov 1, 2018

Live SDK and Live Connect APIs have been marked as deprecated for over a year. As announced on the Office Developer blog, these APIs are now end of life and will no longer be available after November 1, 2018.

Profile and contacts data will no longer be available from the Live Connect APIs as of Decmeber 1, 2017. Calendar data has not been available from Live Connect since June 2017.

https://docs.microsoft.com/en-us/onedrive/developer/rest-api/concepts/migrating-from-live-sdk?view=odsp-graph-online

Download URL

Hi @krizalys

is it possible to get the download URL via:

   ```

$data = fopen($path_file, 'rb');
$uploadSession = $dataItem->startUpload(basename($path_file), $data);
$uploadedFile = $uploadSession->complete();
$download_link = $dataItem->download();

the `$download_link` is giving an error not found:

`{ "error": { "code": "itemNotFound", "message": "You cannot get content for a folder", "innerError": `

How to get Refresh Token?

How can I get Refresh Token? I am using getState function but I only get Access Token.

Please help me with this issue. Thanks.

Over 4MB size

Hey,

I guess if I misunderstood, we don't have a chance to upload files over 4 MB, right?

Thank you @krizalys

hashes not present for files

now OneDrive provides files with hashes,,,, but in your eamples file object return without hash is there any problem with code or are u using old api

Can we download a file?

So just a question, cause in the example it doesn't seem possible, but can you actually download a file from onedrive with this tool? for what we want to use this project for we pretty much need that.
If not, could you maybe guide me in the right direction for how to do that?
Since im not really used to big projects with custom objects(onedrive object) etc xd i tend to make wordpress plugins mostly.

Cannot use token from state

I find there is no way to use a access token stored in state options.
There is only one setAccessToken called in obtain token from code.
$this->graph->setAccessToken($this->_state->token->data->access_token);

Potential Fatal Error when Refreshing Token

Hi! I'm getting a fatal error at this HTTP Request:
https://github.com/krizalys/onedrive-php-sdk/blob/master/src/Client.php#L418

I could be wrong, but I just recently enabled 2FA on my Microsoft Account, and that may have had something to do with what's going on. The error is:

[04-Feb-2020 16:32:44 UTC] PHP Fatal error:  Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://login.microsoftonline.com/common/oauth2/v2.0/token` resulted in a `400 Bad Request` response:
{"error":"invalid_grant","error_description":"AADSTS70000: The provided value for the 'code' parameter is not valid.\r\n (truncated...)
 in /vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 /vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 ... in /vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113

What I feel like could be happening is:

  1. Authorize Application
  2. Store Access/Refresh Token
  3. Modify/Enable 2FA settings on Authenticated account
  4. Attempt to use application
  5. Get Fatal Error during $client->renewAccessToken().

I'm still not 100% sure enabling 2FA has cause the problem, but wanted to get your feedback to see what could be the issue and/or if you could reproduce it.

Stream must be a resource

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Stream must be a resource' in /home3/o3j3v5e1/public_html/onedrive/vendor/guzzlehttp/psr7/src/Stream.php:49 Stack trace: #0 /home3/o3j3v5e1/public_html/onedrive/vendor/microsoft/microsoft-graph/src/Http/GraphResponse.php(157): GuzzleHttp\Psr7\Stream->__construct(Array) #1 /home3/o3j3v5e1/public_html/onedrive/vendor/krizalys/onedrive-php-sdk/src/Proxy/DriveItemProxy.php(368): Microsoft\Graph\Http\GraphResponse->getResponseAsObject('GuzzleHttp\Psr7...') #2 /home3/o3j3v5e1/public_html/onedrive/redirect.php(45): Krizalys\Onedrive\Proxy\DriveItemProxy->download('hello123.txt') #3 {main} thrown in /home3/o3j3v5e1/public_html/onedrive/vendor/guzzlehttp/psr7/src/Stream.php on line 49

Separate out HTTP consumer, or use Guzzle

This library contains its own private functions for calling curl, which is a bit inflexible.

It'd be best to either:

  1. Separate out the HTTP consumer into a separate class, and pass that... e.g.:
$consumer = new \OneDrive\Curl_Consumer(); // Object which contains all the current HTTP classes used in this SDK
$onedrive = new \OneDrive\Client($options, $consumer); // Consumer is passed to client, which calls its methods

This allows someone to build their own replacement consumer class, whilst still having curl available as a convenient default for people who don't need to do anything fancy.

or

  1. Use Guzzle, which is flexible enough to allow pretty much anything to be done with it, and isn't tied to curl (though defaults to curl). Guzzle is used in this way by the Amazon Web Services and Rackspace OpenCloud PHP SDKs, amongst others.

This isn't so exciting or needful to me that I'm likely to do it (though I'd probably use it if it were provided). I just mention it as something that would be an improvement.

how does another user pull the file list ?

Sorry for my bad english. I used api and started it. example:

$deger = $client->getDriveItemById('680B****!2777');
echo 'parent Id : '.$deger->parentReference->id .'</br>';
echo 'id : '.$deger->id .'</br>';
echo 'name : '.$deger->name .'</br>';
echo 'web Url : '.$deger->webUrl.'</br>';

This code work well, output:

parent Id : 680BF**!2773
id : 680BFF**!2777
name : musteri kabul.xlsx
web Url : https://1drv.ms/x/s!A***wtolVk

But if i user another user. an error occurs. this is the error:

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: GET https://graph.microsoft.com/v1.0/me/drive/items/680BFF***!2777 resulted in a 404 Not Found response: { "error": { "code": "itemNotFound", "message": "Item does not exist", "innerError": { "request (truncated...) in C:\wamp64\www\exe\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:113 Stack trace: #0 C:\wamp64\www\exe\vendor\guzzlehttp\guzzle\src\Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 C:\wamp64\www\exe\vendor\guzzlehttp\promises\src\Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response)) #2 C:\wamp64\www\exe\vendor\guzzlehttp\promises\src\Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array) #3 C:\wamp64\www\exe\vendor\guzzlehttp\promises\src\TaskQueue.php(47): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise{closure} in C:\wamp64\www\exe\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 113

I think it's a problem of access. If the user goes to the link "Url : https://1drv.ms/x/s!A***wtolVk" . He can open that link. What can i do ??

thanks in advance

Problem uploading larger file

Hello
Awesome library, I thank you for it :)
I have a problem. When I upload a larger file, I get this:
Severity: Error --> Allowed memory size of 268435456 bytes exhausted (tried to allocate 115351552 bytes) /home/onlblcm/dev.blasteronline.com/application/libraries/onedrive-php-sdk-master/src/Krizalys/Onedrive/Client.php 791

How can this be fixed?
Can the file be split or what can I do?

Thanks
Vlad

Upload created tmp file and uploadurl not showing

@krizalys hi, this actually worked but i got ~tmpxxx file created inside my folder. How can i get rid of that?
i used this exact code:

$stream = fopen($path_to_file_being_uploaded, 'rb');
$upload = $folder->startUpload(basename($path_to_file_being_uploaded), $stream);

And after complete upload i would like to get the upload URL but no luck:

$driveItem = $upload->complete();
$permission = $upload->uploadUrl;

i thought i would get the URL by $driveItem->uploadUrl;

but still no luck.

Thanks!

authentication not working after following all the instruction. Please help

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: POST https://login.microsoftonline.com/common/oauth2/v2.0/token resulted in a 400 Bad Request response: {"error":"invalid_request","error_description":"AADSTS50194: Application '24a468f9-d56f-4259-984f-36bd0012f799'(test-app (truncated...) in /Users/apurbapodder/public_folder/chunk-upload/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113 Stack trace: #0 /Users/apurbapodder/public_folder/chunk-upload/vendor/guzzlehttp/guzzle/src/Middleware.php(65): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response)) #1 /Users/apurbapodder/public_folder/chunk-upload/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response)) #2 /Users/apurbapodder/public_folder/chunk-upload/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array) #3 /Users/apurbapod in /Users/apurbapodder/public_folder/chunk-upload/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113

Third party user upload file using pre-defined credential marked on the program

Hi Christophe,

I would like to build a page for user to login using our pre-defined login account, not OneDrive account, to upload file to our OneDrive folder. The OneDrive authentication information is hard code on the php page beforehand. Is it feasible? I want to let user upload files without knowing they are uploading to OneDrive. Please advise. Much thanks.

Joanne

Is it possible to connect/upload to a onedrive business account?

When i request the granting from the user who tries to log in with a business account we got an error message, that this account is not a Microsoft account. So we can not upload to a onedrive business account ([email protected]), too.
What should i do/change to be able to upload to both a personal account (this is working) or to a business account (this isn't working), depending by the granting user?

Redirect login without login page

Hi @krizalys , lame question here but i am really confused on how to implement your code without login in. I am working with sites to upload into my onedrive business app and i dont want them to login using my credentials. Can you help me with this please.

I have this short script but authentication is not working, i was basing this on the example testing you made. https://prnt.sc/ps1mh3

Thanks!

upload image from url

Hi,
I trying to upload image using your example create-file.php.
in the content field i give full image url and give the image name.jpg
when i go to my onedrive, i see the file but the file is corrupted.

so how can i upload image that will work?

Thanks

[Support] 503 Service Unavailable

So, in a different ticket, I got some sample code for handling file uploads. One of our users is experiencing issues uploading a 114MB file, with the error log reporting:

Server error: `PUT https://domainname-my.sharepoint.com/personal/accountname/_api/v2.0/drives/REDACTED/items/REDACTED/uploadSession?guid='1a4dc0c6-10e1-4ba7-b5a5-8adf10cb4ce8'&path='~tmpDC_backup-domainname-2019_12_06-11_11am-full-h3n9rtr9a3.zip'&overwrite=True&rename=False&dc=0&tempauth=REDACTED|some really long string of text|REDACTED` resulted in a `503 Service Unavailable` response:
{"error":{"code":"serviceNotAvailable","message":"Service unavailable","retryAfterSeconds":120}}

Any idea what could be the cause of this? 114MB hardly seems large enough to be causing the issue, although smaller files have successfully uploaded. Could there be server limitations? Where do I need to look to pinpoint this problem?

Somewhat of a side question, once startUpload() is called, is there a way to stop/cancel the transfer?

Create new release (on packagist)

Currently, v1.0.0 is very old and virtually unusable (too many bugs). One cannot simply use this package from composer (unless they resort to using dev-master, which isn't good practice).

Since so far there have been tonnes of actual bug fixes (and not so much breaking changes AFAIK), it would be a good idea to create a release some time soon.

How to setup the example with http?

I cannot add a http redirect url in my application management page of microsoft account...
how to setup it? I cannot use https in that server.

Onedrive Business

Does this support Onedrive for business? I guess Onedrive business has different approach on the api, they have different APi endpoint where the tenant is needed on the URL. I just wanted to know how I can achieve it through this wrapper you made.

how do i upload the file ?

I looked but I couldn't find. All examples request names and content like that :
public function upload($name, $content, array $options = [])

But i want to upload an existing file on the my computer. Can you help me ?

Onedrive novice - help needed

Hi,
I have a requirement to allow users logged into to our company-use-only website to upload/download files from known folders. Currently am using Dropbox but would now like to use Onedrive, I not have to login separately to Onedrive (as user has already authenticated and identified themselves logging into our main website).
Is this code that can do that ?

Can you confirm it is not going to be out of date / deprecated soon ?
Compared to Dropbox the development learning curve seems a bit steeper requiring

  • A OneDrive web application configured with http://localhost:7777/ as its redirect URL
  • A WebDriver server, for example the Selenium's Java standalone server
  • A Chrome browser & ChromeDriver, and they must be usable by the WebDriver server

To date I just use a local xampp setup to develop on and then upload to a shared web server.

Any advice to get over this hurdle welcome .

Thanks

Save files to OneDrive using PHP but same FTP without show login page for access_token

I'm wondering if I can use OneDrive for saving integration files between two web apps, so I have to create file and save it to OneDrive on specific folder but this process should be in background using username and password for OneDrive account, so the end user should not see the Microsoft login page or asking them about this app to allow access to his info, (by the way I don't need any information from end user) All what I want is to upload the integration files to specific OneDrive account on specific action exactly same FTP on PHP.

Please any suggestions or solutions?

Handling Large File Uploads (Example/Support Request)

Hi! Thanks again for all the work on this library. I'm trying to find an example of how to best use the startUpload() method and the UploadSessionProxy object. Excuse my ignorance, but does this work "automagically" or do I need to monitor progress, resume upload, detect completion, etc? The only example I could find was:

$uploadSession1 = $driveItem->startUpload(
    'file.txt',
    'Some other content',
    [
        'conflictBehavior' => ConflictBehavior::RENAME,
        'type'             => 'text/plain',
    ]
);

$childDriveItem = $uploadSession1->complete();

My questions are:

  1. Should 'type' be 'contentType'? I've seen both used and wondered which is correct.
  2. Is file_get_contents( $path_to_file_being_uploaded ) an acceptable value for the 2nd parameter ($content)? There are some other open tickets/support mentioning a Stream should be used. Do you have an example for that? Is that better?
  3. What is the behavior of $uploadSession1->complete()? Is this a value that should be stored, and used again when resuming an incomplete upload? How can I tell when it's finished and/or if it was successful? The documentation isn't clear on how to get this information. It only appears to return a DriveItemProxy or throw an exception.

I'm mostly looking for a thorough example on how to use startUpload().

Lastly, is it safe to ALWAYS use startUpload() vs just using upload() if the file is smaller and can be uploaded via a single upload session?

Thanks!

create file warning

when I am using create file show curl error

$parentId = null;
$name = 'sample.txt';
$content = 'this is sample text';
$parent = $onedrive->fetchObject($parentId);
$file = $parent->createFile($name, $content);

var_dump($file->getName().' : '.$file->getId());

Warning: curl_setopt_array(): cannot represent a stream of type MEMORY as a STDIO FILE in in onedrive-php-sdk-master\src\Krizalys\Onedrive\Client.php on line 515

file create but contents not saved

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.