[英]how to access sharepoint folder using graph api
In my SharePoint site Document Library, I have a folder called OneDriveInventory and I have a few file inside.在我的 SharePoint 站点文档库中,我有一个名为 OneDriveInventory 的文件夹,里面有一些文件。
I'm trying to access those file but it look like my Uri request is wrong so I would be really appreciated I can get any help or suggestion on how to fix this.我正在尝试访问这些文件,但看起来我的 Uri 请求是错误的,所以我将不胜感激,因为我可以获得有关如何解决此问题的任何帮助或建议。
Invoke-WebRequest -Uri "https://graph.microsoft.com/v1.0/sites/$siteId/drives/$driveId/OneDriveInventory/$($filename)" -Method GET -OutFile $filePath -Headers $headers
I tried to reproduce the same in my environment and got below results:我试图在我的环境中重现相同的结果并得到以下结果:
I have one SharePoint document library in which I created folder named OneDriveInventory
and added files like below:我有一个 SharePoint 文档库,我在其中创建了名为
OneDriveInventory
的文件夹并添加了如下文件:
You can make use of below Graph API call to access file in the above folder:您可以使用下面的Graph API 调用来访问上述文件夹中的文件:
GET https://graph.microsoft.com/v1.0/sites/<siteID>/drives/<driveID>/root:/OneDriveInventory:/children/<filename>
When I ran the above query in Graph Explorer , I got results successfully like below:当我在Graph Explorer中运行上述查询时,我成功地得到了如下结果:
To get the same results from PowerShell, I registered one Azure AD application and added API permissions like below:为了从 PowerShell 获得相同的结果,我注册了一个 Azure AD 应用程序并添加了API 权限,如下所示:
Now I generated access token using below PowerShell script:现在我使用下面的 PowerShell 脚本生成了访问令牌:
$tenantId = <tenantID>
$applicationId = <appID>
$secret= <secret>
$param = @{
Uri = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token";
Method = 'Post';
Body = @{
grant_type = 'client_credentials';
scope = 'https://graph.microsoft.com/.default';
client_id = $applicationId;
client_secret = $secret
}
}
$result = Invoke-RestMethod @param
$token = $result.access_token
Response:回复:
To access file from folder, I used below PowerShell script:要从文件夹访问文件,我使用了以下 PowerShell 脚本:
$siteID = "3b23b598-f5e4-461f-b038-xxxxxx"
$driveID = "xxxxxxxxxxxxxxxxxxx"
$filename = "sridevi.txt"
$headers=@{}
$headers.Add("Content-Type", "text/plain")
$headers.Add("Authorization", "Bearer $token")
$response=Invoke-WebRequest -Uri "https://graph.microsoft.com/v1.0/sites/$siteID/drives/$driveID/root:/OneDriveInventory:/children/$($filename)" -Method GET -OutFile $filePath -Headers $headers
Response:回复:
When I ran $response.Content
, I got full response like below:当我运行
$response.Content
时,我得到了如下的完整响应:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.