写在前面
最近一直在搞通过Rest api的方式读取sharepoint文档库中的内容。有些地方需要注意,在此做下记录。
步骤
启动sharepoint服务器的服务
这里可以使用脚本的方式进行启动,脚本如下:
获得管理账户,比如你的账户为sp\administrator
$account = Get-SPManagedAccount "sp\administrator" $subscriptionSettingsServices = Get-SPServiceInstance | where {$_.TypeName -like "Microsoft SharePoint Foundation Subscription Settings Service"} | ForEach-Object { $subscriptionSettingsService = $_; if($subscriptionSettingsService.Status -ne "Online") { Write-Host "start Subscription Settings Service ,Id:" + $_.Id Start-SPServiceInstance $subscriptionSettingsService | Out-Null } else{ Write-Host "Subscription Settings Service has started,Id:" + $_.Id } } Write-Host "starting Config Subscription Settings Service..." $appPoolSubSvc = New-SPServiceApplicationPool -Name SettingsServiceAppPool -Account $account $appSubSvc = New-SPSubscriptionSettingsServiceApplication –ApplicationPool $appPoolSubSvc –Name SettingsServiceApp –DatabaseName SettingsServiceDB_tmp $proxySubSvc = New-SPSubscriptionSettingsServiceApplicationProxy –ServiceApplication $appSubSvc $AppManageServices = Get-SPServiceInstance | where {$_.TypeName -like "App Management service"} | ForEach-Object { $AppManageService = $_; if($AppManageService.Status -ne "Online") { Write-Host "start run App Management service ,Id:" + $_.Id Start-SPServiceInstance $AppManageService | Out-Null } else{ Write-Host "App Management service has started,Id:" + $_.Id } } Write-Host "App Management service..." $appPoolSubSvc = New-SPServiceApplicationPool -Name AppManagementServiceAppPool -Account $account $appSubSvc = New-SPAppManagementServiceApplication –ApplicationPool $appPoolSubSvc –Name AppManagementServiceApp –DatabaseName AppManagementServiceDB_tmp $proxySubSvc = New-SPAppManagementServiceApplicationProxy –ServiceApplication $appSubSvc Write-Host "config success!"
运行成功后检查下列服务是否启动:
检查下列服务是否存在:
准备证书
创建并导出自签名的证书
导出公钥证书
注册APP并授权
注册app的脚本
$serviceConfig = Get-SPSecurityTokenServiceConfig $serviceConfig.AllowOAuthOverHttp = $true $serviceConfig.Update() $appDisplayName = "Lenovo_Documents" $clientID = "11c825ca-5b9c-4a02-857d-d0bc9690c327" $targetSiteUrl = "http://sp2013/" $targetSite = Get-SPSite $targetSiteUrl $realm = Get-SPAuthenticationRealm -ServiceContext $targetSite $fullAppPrincipalIdentifier = $clientID + "@" + $realm Write-Host "Register new app principal" $registeredAppPrincipal = Register-SPAppPrincipal -NameIdentifier $fullAppPrincipalIdentifier -Site $targetSite.RootWeb -DisplayName $AppDisplayName Set-SPAppPrincipalPermission -site $targetSite.RootWeb -AppPrincipal $registeredAppPrincipal -Scope SiteCollection -Right FullControl -EnableAppOnlyPolicy
注册发布者
#Register a trusted security-token issuer $targetSiteUrl = "http://sp2013/" $publicCertificatePath = "C:\Certs\Lenovo_Documents.cer" $issuerID = "7c444f28-03be-445f-8Dfc-0af2869b23cd" $targetSite = Get-SPSite $targetSiteUrl $realm = Get-SPAuthenticationRealm -ServiceContext $targetSite $realm $registeredIssuerName = $issuerID + "@" + $realm $publicCertificate = Get-PfxCertificate $publicCertificatePath Write-Host "Create token issuer" $secureTokenIssuer = New-SPTrustedSecurityTokenIssuer -Name $issuerID -RegisteredIssuerName $registeredIssuerName -Certificate $publicCertificate -IsTrustBroker iisreset
开发app,消费sharepoint数据
创建网站
添加引用
加入TokenHelper.cs
配置Web.Config
注意下列标记值,应与之前步骤配置的值一致。注意,在下面的对应的guid,应与注册时候使用的guid相同。
如预期,通过REST API 返回JSON数据
总结
如果在sharepoint的本地环境中调试通过,然后就是通过odata方式获取,或者筛选自己需要的数据了。
时间: 2024-11-08 06:57:14