php 如何将sharepoint与php连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17545824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:04:53  来源:igfitidea点击:

how to connect sharepoint with php

phpsharepointsoapsharepoint-2013

提问by samjhana joshi

Do anyone know how to integrate Sharepoint and Php. I am trying to develop php app which can connect to Sharepoint.In particular since basically I am website developer, I want my all websites to be connected with Sharepoint. So, simply I want to create Php app such that it works for all the websites. I don't know is it possible or not but I want to give it a try but don't know how to proceed.

有谁知道如何集成Sharepoint和Php。我正在尝试开发可以连接到 Sharepoint 的 php 应用程序。特别是因为基本上我是网站开发人员,我希望我的所有网站都与 Sharepoint 连接。所以,我只想创建 PHP 应用程序,使其适用于所有网站。我不知道是否可能,但我想尝试一下,但不知道如何进行。

Any idea/suggestions is welcome.

欢迎任何想法/建议。

Thanks in advance.

提前致谢。

回答by NoodleFolk

Try this API

试试这个API

In SharePoint

在 SharePoint 中

Download the WSDL. Usually at this location: <sharepoint.url>/subsite/_vti_bin/Lists.asmx?WSDL

下载 WSDL。通常在这个位置:<sharepoint.url>/subsite/_vti_bin/Lists.asmx?WSDL

Download the API

下载 API

Make sure to save both SoapClientAuth.phpand SharePointAPI.php

确保同时保存SoapClientAuth.phpSharePointAPI.php

In PHP

在 PHP 中

// 0: include api in your php script.
require_once('SharePointAPI.php');

// 1: connect to SharePoint
$sp = new SharePointAPI('<username>', '<password>', '<path_to_WSDL>');

// 2: read a list
$listContents = $sp->read('<list_name>'); 

// 3: now you have a 2-D array to work with in PHP
foreach($listContents as $item)
{
    var_dump($item);
}

With this API, you can also query, update, create, delete lists, query list metadata

使用此 API,您还可以查询、更新、创建、删除列表,查询列表元数据

回答by Robbert

If I read your question right, you want to interact with your SharePoint site using PHP. You can do most interaction by using SharePoint's web services. For instance, you can read all list items using the lists web service (http:///_vti_bin/lists.asmx). You can upload files to a SharePoint document library. I searched furiously for an example of what I did to accomplish that, but I have lost it. I remember using Curl to do the uploads.

如果我没看错您的问题,您希望使用 PHP 与您的 SharePoint 网站进行交互。您可以使用 SharePoint 的 Web 服务进行大多数交互。例如,您可以使用列表 Web 服务 (http:///_vti_bin/lists.asmx) 读取所有列表项。您可以将文件上传到 SharePoint 文档库。我疯狂地寻找我为实现这一目标所做的工作的例子,但我已经失去了它。我记得使用 Curl 进行上传。

There are a number of websites that discuss using PHP to access SharePoint data. Here are a couple that I found with a simple google search:

有许多网站讨论使用 PHP 访问 SharePoint 数据。以下是我通过简单的谷歌搜索找到的几个:

As well as a discussion about a tool called Camelot PHP here

以及这里关于名为 Camelot PHP 的工具的讨论

回答by Yogi Ghorecha

I have used this in API to connect my PHP web application with SharePoint and transferring data From PHP to SharePoint, it worked 100% for me:

我在 API 中使用它来连接我的 PHP Web 应用程序和 SharePoint 并将数据从 PHP 传输到 SharePoint,它对我来说 100% 工作:

Usage Instructions:

使用说明

Installation

安装

Download the WSDL file for the SharePoint Lists you want to interact with. This can normally be obtained at:sharepoint.url/subsite/_vti_bin/Lists.asmx?WSDL

下载要与之交互的 SharePoint 列表的 WSDL 文件。这通常可以在以下位置获得:sharepoint.url/subsite/_vti_bin/Lists.asmx?WSDL

If you are using composer, just add thybag/php-sharepoint-lists-api to your composer.json and run composer.

如果您使用的是 composer,只需将 thybag/php-sharepoint-lists-api 添加到您的 composer.json 并运行 composer。

    {
    "require": {
        "thybag/php-sharepoint-lists-api": "dev-master"
    }
    }

If you are not using composer you can download a copy of the SharePoint API files manually and include the top "SharePointAPI.php" class in your project.

如果您没有使用 Composer,您可以手动下载 SharePoint API 文件的副本,并在您的项目中包含顶部的“SharePointAPI.php”类。

Creating SharePointAPI object

创建 SharePointAPI 对象

In order to use the PHP SharePoint Lists API you will need a valid user/service account with the permissions to the required list.

为了使用 PHP SharePoint 列表 API,您需要一个具有所需列表权限的有效用户/服务帐户。

For most SharePoint installations, you can create a new instance of the API using:

对于大多数 SharePoint 安装,您可以使用以下方法创建 API 的新实例:

    use Thybag\SharePointAPI;
            $sp = new SharePointAPI('', '', '');

If your installation requires NTLM Authentication, you can instead use:

如果您的安装需要 NTLM 身份验证,您可以改为使用:

    use Thybag\SharePointAPI;
    $sp = new SharePointAPI('', '', '', 'NTLM');

SharePoint Online users must use:

SharePoint Online 用户必须使用:

    use Thybag\SharePointAPI;
    $sp = new SharePointAPI('', '', '', 'SPONLINE');

All methods return an Array by default. SetReturnType can be used to specify that results should be returned as objects instead.

默认情况下,所有方法都返回一个数组。SetReturnType 可用于指定结果应作为对象返回。

Reading from a List.

从列表中读取。

To return all items from a list use either

要从列表中返回所有项目,请使用

    $sp->read('');
or
    $sp->query('')->get();

To return only the first 10 items from a list use:

要仅返回列表中的前 10 个项目,请使用:

    $sp->read('', 10);

or

或者

    $sp->query('')->limit(10)->get();

To return all the items from a list where surname is smith use:

要从姓氏为 smith 的列表中返回所有项目,请使用:

    $sp->read('', NULL, array('surname'=>'smith'));

or

或者

    $sp->query('')->where('surname', '=', 'smith')->get();

Querying a list

查询列表

The query method can be used when you need to specify a query that is to complex to be easily defined using the read methods. Queries are constructed using a number of (hopefully expressive) pseudo SQL methods.

当您需要指定一个非常复杂的查询以使用 read 方法轻松定义时,可以使用 query 方法。查询是使用许多(希望具有表现力的)伪 SQL 方法构建的。

If you, for example, wanted to query a list of pets and return all dogs below the age of 5 (sorted by age) you could use.

例如,如果您想查询宠物列表并返回所有 5 岁以下的狗(按年龄排序),您可以使用。


    $sp->query('list of pets')->where('type','=','dog')->and_where('age','sort('age','ASC')->get();

If you wanted to get the first 10 pets that were either cats or hamsters you could use:

如果您想获得前 10 只猫或仓鼠的宠物,您可以使用:

    $sp->query('list of pets')->where('type','=','cat')->or_where('type','=','hamster')->limit(10)->get();

If you need to return 5 items, but including all fields contained in a list, you can use. (pass false to all_fields to include hidden fields).

如果您需要返回 5 个项目,但包括列表中包含的所有字段,则可以使用。(将 false 传递给 all_fields 以包含隐藏字段)。

    $sp->query('list of pets')->all_fields()->get();

If you have a set of CAML for a specific advanced query you would like to run, you can pass it to the query object using:

如果您有一组要运行的特定高级查询的 CAML,您可以使用以下命令将其传递给查询对象:

    $sp->query('list of pets')->raw_where('Hello World')->limit(10)->get();

Adding to a list

添加到列表

To add a new item to a list you can use either the method "write", "add" or "insert" (all function identically). Creating a new record in a List with the columns forename, surname, age and phone may look like:

要将新项目添加到列表中,您可以使用“写入”、“添加”或“插入”方法(所有功能都相同)。在列表中创建一个包含姓名、姓氏、年龄和电话列的新记录可能如下所示:

    $sp->write('', array('forename'=>'Bob','surname' =>'Smith', 'age'=>40, 'phone'=>'(00000) 000000' ));

You can also run multiple write operations together by using:

您还可以使用以下命令同时运行多个写入操作:

    $sp->writeMultiple('', array(array('forename' => 'James'),array('forename' => 'Steve')));

Editing Rows

编辑行

To edit a row you need to have its ID. Assuming the above row had the ID 5, we could change Bob's name to James with:

要编辑一行,您需要有它的 ID。假设上面一行的 ID 为 5,我们可以将 Bob 的名字改为 James:

    $sp->update('','5', array('forename'=>'James'));/code>

As with the write method you can also run multiple update operations together by using:

    $sp->updateMultiple('', array(    array('ID'=>5,'job'=>'Intern'),array('ID'=>6,'job'=>'Intern')));

When using updateMultiple every item MUST have an ID.

Deleting Rows

In order to delete a row, an ID, as well as list name, is required. To remove the record for James with the ID 5 you would use:

    $sp->delete('', '5');

If you wished to delete a number of records at once, an array of ID's can also be passed to the delete multiple methods

    $sp->deleteMultiple('', array('6','7','8'));

Helper methods

The PHP SharePoint API contains a number of helper methods to make it easier to ensure certain values are in the correct format for some of SharePoint special data types.

dateTime The DateTime method can either be passed a text-based date

    $date = \Thybag\SharepointApi::dateTime("2012-12-21");

Or a unix timestamp

    $date = \Thybag\SharepointApi::dateTime(time(), true);

Troubleshooting

Unable to find the wrapper "https"

If you are getting this error it normally means that php_openssl (needed to curl https URLs) is not enabled on your web server. With many local web servers (such as XAMPP) you can simply open your php.ini file and uncomment the php_openssl line (ie. remove the; before it).

Note: If you are using SharePoint Online and having SSL errors, please pull the latest version which has changed from SSL v3 to TLS for SharePoint online connections.

Add this line to your composer.json file

As with the write method you can also run multiple update operations together by using:

    $sp->updateMultiple('', array(    array('ID'=>5,'job'=>'Intern'),array('ID'=>6,'job'=>'Intern')));

When using updateMultiple every item MUST have an ID.

Deleting Rows

In order to delete a row, an ID, as well as list name, is required. To remove the record for James with the ID 5 you would use:

    $sp->delete('', '5');

If you wished to delete a number of records at once, an array of ID's can also be passed to the delete multiple methods

    $sp->deleteMultiple('', array('6','7','8'));

Helper methods

The PHP SharePoint API contains a number of helper methods to make it easier to ensure certain values are in the correct format for some of SharePoint special data types.

dateTime The DateTime method can either be passed a text-based date

    $date = \Thybag\SharepointApi::dateTime("2012-12-21");

Or a unix timestamp

    $date = \Thybag\SharepointApi::dateTime(time(), true);

Troubleshooting

Unable to find the wrapper "https"

If you are getting this error it normally means that php_openssl (needed to curl https URLs) is not enabled on your web server. With many local web servers (such as XAMPP) you can simply open your php.ini file and uncomment the php_openssl line (ie. remove the; before it).

Note: If you are using SharePoint Online and having SSL errors, please pull the latest version which has changed from SSL v3 to TLS for SharePoint online connections.

Add this line to your composer.json file

    thybag/php-sharepoint-lists-api: dev-develop

You can perform CRUD (Create/Read/Update/Delete) operation with above SharePoint API.

您可以使用上述 SharePoint API 执行 CRUD(创建/读取/更新/删除)操作。

Reference URL link: https://github.com/thybag/PHP-SharePoint-Lists-API

参考网址链接:https: //github.com/thybag/PHP-SharePoint-Lists-API