通过 microsoft graph api 从共享点网站获取新闻

问题描述 投票:0回答:2

我已经被困在通过 microsoft graph api 从共享点网站获取新闻有一段时间了,这是我最后的手段。 我已经多次浏览了 microsoft graph api,并且发现了如何使用工作 microsoft 帐户来获取我所属的网站,这可以很好地工作:https://learn.microsoft.com/en -us/graph/api/resources/site?view=graph-rest-1.0

但是我不知道从这里到哪里去获取在共享点网站上创建的新闻,也许有人可以指导我正确的方向,从哪里获取这些新闻?

我已经多次尝试查看微软图形文档,我已经尝试了与网站有关的所有内容,但只得到了该帐户所属网站的列表。 我尝试寻找解决方案但没有成功。

这是我用来获取共享点站点列表的方法:

/sites?search=*&$select=id,displayName,description,webUrl,sharepointIds
php sharepoint microsoft-graph-api
2个回答
0
投票

我想我已经弄清楚了,但我不确定为什么如果我在同一个流程中执行它则不起作用,所以我必须做的是调用 microsoft graph api(我通过 league 这样做。

        $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后,我使用上一步中的frefresh_token,使用curl获取共享点在线access_token和refresh_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);

我尝试一步完成所有工作,但由于某种原因我无法实现它,如果我找到一种方法,我会更新这篇文章。


0
投票

您能提供图形 API 调用来返回新闻报道吗?

© www.soinside.com 2019 - 2024. All rights reserved.