如何使用php连接sharepoint

时间:2013-07-09 10:24:45

标签: php sharepoint soap sharepoint-2013

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

欢迎任何想法/建议。

提前致谢。

3 个答案:

答案 0 :(得分:8)

试试这个API

在SharePoint中

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

下载API

确保同时保存SoapClientAuth.phpSharePointAPI.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);
}

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

答案 1 :(得分:1)

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

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

以及关于名为Camelot PHP here

的工具的讨论

答案 2 :(得分:1)

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

使用说明

<强>安装

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

获得

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

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

如果您不使用编写器,则可以手动下载SharePoint API文件的副本,并包含顶部&#34; SharePointAPI.php&#34;你的项目中的课程。

创建SharePointAPI对象

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

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

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

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

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

SharePoint Online用户必须使用:

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

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

从列表中读取。

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

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

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

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

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

要返回姓氏为史密斯使用的列表中的所有项目:

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

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

查询列表

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

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


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

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

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

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

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

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

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

添加到列表

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

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

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

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

编辑行

要编辑行,您需要拥有其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

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

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

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