有一段时间以来,我一直被困在通过microsoft图形api从sharepoint站点获取消息上,这是我最后的选择。我已经多次查看microsoft图形api,并且我已经了解了如何使用microsoft帐户来获得我所在的站点,通过以下内容可以很好地工作:https://learn.microsoft.com/en-us/graph/api/resources/site?view=graph-rest-1.0。
但是我不知道从哪里可以从这里得到在sharepoint网站上创建的新闻,也许有人可以引导我从哪里得到这些信息?
我已经尝试过多次查看微软的图表文档,我已经尝试了所有与站点相关的东西,并且只得到了帐户所包含的站点列表。我试着找一个没有运气的解决办法。
这是我用来获取sharepoint站点列表的内容:
/sites?search=*&$select=id,displayName,description,webUrl,sharepointIds发布于 2022-10-28 16:37:37
我想我已经知道了,但我不知道如果我在相同的流程中这样做,它为什么不能工作,所以我要做的就是调用microsoft图形api (我是通过联盟这样做的)。
$oauthClient = new \League\OAuth2\Client\Provider\GenericProvider([
'clientId' => $this->clientId,
'clientSecret' => $this->clientSecret,
'redirectUri' => "<redirect url>",
'urlAuthorize' => "https://login.microsoftonline.com/<tenant id>/oauth2/v2.0/authorize",
'urlAccessToken' => "https://login.microsoftonline.com/<tenant id>/oauth2/v2.0/token",
'urlResourceOwnerDetails' => '',
'scopes' => "openid profile User.Read offline_access Sites.Read.All",
]);
$accessToken = $oauthClient->getAccessToken("authorization_code", ['code' => $authorization_code]);在获得access_token和refresh_token之后,我使用curl来获取sharepoint access_token和refresh_token,方法是使用前面步骤中的frefresh_token:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://login.microsoftonline.com/<tenant id>/oauth2/v2.0/token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "client_id=<client id>&client_secret=<client secret>&refresh_token=<refresh token from the previous step>&grant_type=refresh_token&scope=https%3A%2F%<tenant name>.sharepoint.com%2FSites.Read.All",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/x-www-form-urlencoded"
),
));
$SPOResponse = curl_exec($curl);
$SPOResponse = json_decode($SPOResponse);
$SPOHttpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);我试着让这一切在一步内完成,但由于某些原因我无法做到,如果我找到了更新这篇文章的方法。
https://stackoverflow.com/questions/74225044
复制相似问题