Reputation: 58
I have been stuck at getting the news from sharepoint sites through the microsoft graph api for a while now, and this is my last resort. I have been going through the microsoft graph api multiple times and I have found out how to use a work microsoft account to get the sites I am part of, which works fine through this: https://learn.microsoft.com/en-us/graph/api/resources/site?view=graph-rest-1.0
But I cannot figure out where to go from here to get the news that has been created on sharepoint sites, and maybe someone can guide me in the right direction on where to get these?
I have tried going over the microsoft graph documentation multiple times, I have tried everythingg that has to do with sites and only got as far as getting the list of sites the account is part of. I have tried searching for a solution with no luck.
this is what I have used to get the sharepoint sites list:
/sites?search=*&$select=id,displayName,description,webUrl,sharepointIds
Upvotes: 0
Views: 1174
Reputation: 58
I think I have figured it out, but I am not sure why it is not working if I do it in the same flow, so what I had to do was call the microsoft graph api (I do that through 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]);
After I get the access_token and refresh_token I then use curl to get the sharepoint online access_token and refresh_token by using the frefresh_token from the previous step:
$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);
I tried making it all work in 1 step but I could not make it happen for some reason, if I find a way I will update this post.
Upvotes: 0