Rest API的简单应用
2024-08-31 04:33:46
写在前面
最近一直在搞通过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方式获取,或者筛选自己需要的数据了。
最新文章
- C++多线程の条件变量
- IOS 错误 [UIWebView cut:]: unrecognized selector sent to instance
- [No000044]你是否还傻到把最好的留在最后?
- Javascript添加事件的addEventListener()及attachEvent()区别分析,事件委托
- http的响应对象
- 013医疗项目-模块一:加入工具类ResultUtil
- HTML+css实现图片全屏
- 快书包CEO徐智明反思:我犯下哪些错误
- POJ 3045 Cow Acrobats (贪心)
- 机器学习笔记-1 Linear Regression(week 1)
- 把ipad作为电脑的第二显示器
- struts2 上传与下载
- 解决flutter的image_cropper组件引入报错问题
- JS----对象的合并与克隆
- Android为TV端助力 eclipse出现感叹号的解决办法
- java_注解
- spring4.0之八:Groovy DSL
- Trie树的数组实现原理
- JS之ClassName属性使用
- python---django中模板渲染(csrf令牌使用,自定义模板函数)