如何使用perl脚本从sharepoint获取列表项

时间:2013-05-13 10:19:48

标签: perl sharepoint-2010

我尝试使用perl

从共享点服务器站点获取列表项

script.i我写了脚本,但是给出了错误“401 Unauthorized”。请帮忙解决

这个问题。在这个我是geven域名,用户名,密码也是.on看到凭据。

我在下面写脚本

use LWP::UserAgent;
 use LWP::Debug;
 use Data::Dumper;
use SOAP::Lite on_action => sub { "$_[0]$_[1]"; };
 import SOAP::Data 'name', 'value';
 our $sp_endpoint = 'http://sezdsk22787/_vti_bin/lists.asmx';
 our $sp_domain = 'dev:80';
 our $sp_username = 'spadmin';
 our $sp_password = 'Cmc@1234';
 $debug = 0;
  if ($debug) {
      LWP::Debug::level('+');
   SOAP::Lite->import(+trace => 'all');
 }
 my @ua_args = (keep_alive => 1);
my @credentials = ($sp_domain, "", $sp_username, $sp_password);
 my $schema_ua = LWP::UserAgent->new(@ua_args);
  $schema_ua->credentials(@credentials);
 $soap = SOAP::Lite->proxy($sp_endpoint, @ua_args, credentials => \@credentials);
 $soap->schema->useragent($schema_ua);
 $soap->uri("http://schemas.microsoft.com/sharepoint/soap/GetVersions");

  $lists = $soap->GetListCollection();
 quit(1, $lists->faultstring()) if defined $lists->fault();
  sub lists_getid
  {
  my $title = shift;
  my @result = $lists->dataof('//GetListCollectionResult/Lists/DL_Accounts');
   foreach my $data (@result) {
   my $attr = $data->attr;
         return $attr->{ID} if ($attr->{Title} eq $title);
    }
     return undef;
 }
print "@credentials \n";
 sub lists_getitems
 {
     my $listid = shift;
     my $in_listName = name('listName' => $listid);
     my $in_viewName = name('viewName' => '');
    my $in_rowLimit = name('rowLimit' => 99999);
     my $call = $soap->GetListItems($in_listName, $in_viewName, $in_rowLimit);
     quit(1, $call->faultstring()) if defined $call->fault();
     return $call->dataof('//GetListItemsResult/listitems/data/row');
 }

 my $list_id = lists_getid('Disk Space');
 print "List ID is: $list_id\n";
 my @items = lists_getitems($list_id);
 foreach my $data (@items) {
    my $attr = $data->attr;
    print Dumper($attr);
}

0 个答案:

没有答案