Getting news from sharepoint sites through microsoft graph api - php

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

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.

Related

Unable to fetch response from file_get_contents using PHP

Gurus,
I am trying to fetch tracking details using the austpost.com.au website for which I have written the below code however, it doesn't seem to fetch anything.
$austpost_url = 'https://digitalapi.auspost.com.au/shipmentsgatewayapi/watchlist/shipments/99702032243801004670904';
$options = array(
'method' => 'get',
'contentType' => 'application/json',
'muteHttpExceptions' => true,
'headers' => array ('Accept' => 'application/json, text/plain, */*',
'Accept-Encoding' => 'gzip, deflate, br',
'AP_CHANNEL_NAME' => 'WEB_DETAIL',
'api-key' => 'd11f9456-11c3-456d-9f6d-f7449cb9af8e',
'Connection' => 'keep-alive',
'Origin' => 'https://auspost.com.au',
'Referer' => 'https://auspost.com.au/mypost/track/'),
);
$context = stream_context_create($options);
$html = file_get_contents($austpost_url, false, $context);
echo $html;
Direct Tracking Link: https://auspost.com.au/mypost/track/#/details/99702032243801004670904
I found this by going to the NETWORK tab in Chrome and figured out which request is loading the tracking details. Basically I am just after getting the status of the shipment. Snapshot below:
Any help in this would be much appreciated as I am using PHP to drive my code where I want to update the WordPress posts statuses based on the shipment status (that I can handle) however, stuck here on how I can get this shipment status before I move on.
It is because you need a valid recaptcha token and proof that you are not a robot. Won't be that simple, as you think. The easiest, but paid method, would be to use some captcha solving companies, like https://2captcha.com (not a sponsor of that answer) and their PHP libs.
If you want to use their api, you need to auth with username and password via basic auth. More details in here: https://developers.auspost.com.au/apis/shipping-and-tracking/reference/track-items
First check the fopen is on or off , add the phpinfo(); code in main file and check this .
Otherwise use the Curl function instead of file_get_contents();

"Invalid platform app" error using Instagram Basic Display API

I am trying to use Instagram Basic display API but when I post the authorization code to get the access token I keep getting the following error
{"error_type": "OAuthException", "code": 400, "error_message":
"Invalid platform app"}
I am following all the steps mentioned here -> https://developers.facebook.com/docs/instagram-basic-display-api/getting-started and Yes I am using the Instagram app ID and It's client secret which is in Products -> Instagram -> Display and following is the URL I am sending the request
"https://api.instagram.com/oauth/access_token?client_id=".$app_id."&client_secret=".$app_secret."&grant_type=authorization_code&redirect_uri=".$redirecturi."&code=".$code,
I ran into this same issue. Problem was I was using the Facebook App ID and App Secret instead of the Instagram App ID & App Secret. You must go to the "Instagram Basic Display" section on the Facebook developers site then scroll down until you find the Instagram App ID & Secret.
If you are using Postman, do remember it's a POST request. Use form data
When you exchange the code you need to use a POST request.
From the looks of your url, you've formed it as a GET request with all the parameters as part of the url rather than as form data. Try sending the parameters as part of the post body instead
Working example code:
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.instagram.com/oauth/access_token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => array('client_id' => '{client_id}','client_secret' => '{client_secret}','grant_type' => 'authorization_code','redirect_uri' => '{redirect_uri}','code' => '{code}'),
CURLOPT_HTTPHEADER => array(
"Content-Type: multipart/form-data; boundary=--------------------------780367731654051340650991"
),
));
$response = curl_exec($curl);
curl_close($curl);
print_r($response);
I have got this error for the below reason.
If any case, App Id and Secret Key are blank then this type of error is generated. so we can first test first that that app id and secret key must be the correct one. I know that this is a very normal thing that we can notice easily. But sometimes, we can not notice some simple things.

Update Facebook AdAccount via API

I'm trying to update the payment id on my ad accounts, Is there a way to do this via the API?
Code:
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => "https://graph.facebook.com/v2.10/act_$account_id",
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
'funding_source' => $payment_id,
'access_token' => $access_token
)
));
Getting the following Error: Either the object you are trying to access is not visible to you or the action you are trying to take is restricted to certain account types.
Permissions Error: 200
I am using a system_admin token with all permission, and also tried creating a token with admin permissions, still get the same error.
Reading through the API I can't find any examples of updating an Ad Account.
Is there a way to update the payment (funding_source) id through the API?
Thanks,

Login to Access Facebook data on my Server with FB PHP SDK and Cordova App

I can't figure out the logic flow for a cordova app I am creating. Here is what I want to do.
User is using a Cordova app I am creating and they login to Facebook with a plugin I have (wizcorp Cordova plugin). Nothing in the login process communicates with my own server.
After login my server needs to access some data on my web server in a database that I may have previously saved about this user. (Like posts they have made to their friends through the app).
I need to verify in some PHP code that the user is truly this fb user and not an imposter so I imagine I need to use the access token returned to the user in the app.
I can easily send the token to my PHP code but I can't figure out how to use the PHP Facebook SDK to set this token and get the verified user's Facebook ID.
Here is my PHP code.
require_once("fb/autoload.php");
//Create the Facebook service
$facebook = new Facebook\Facebook ([
'app_id' => '12345',
'app_secret' => '67890',
'default_graph_version' => 'v2.4'
]);
$facebook->setAccessToken($_REQUEST['access_token']);
if (($userId = $facebook->getUser())) {
echo "userId=$userId<br/>";
}
I am getting this error: Call to undefined method Facebook\Facebook::setAccessToken()
curl_setopt_array($curl, array(
CURLOPT_URL => "https://graph.facebook.com/$fb_user_id?fields=id%2Cname&access_token=$access_token",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"cache-control: no-cache",
"postman-token: 3602fbe6-2faf-9c7f-05b0-bcaea8548000"
),
));

Update facebook status using php

I know it's a very old question.But i really bound to ask the same question again.How can i update my status using PHP?Because i find several solutions in google and stackoverflow but non of that currently works.May be the cause of facebook up gradation process or anything else.
I chk:
1) http://360percents.com/posts/php-curl-status-update-working-example-sep-2010/
2) http://www.barattalo.it/2010/03/01/php-curl-bot-to-update-facebook-status/
But unfortunately non of the solution is working.So, is their any kind heart who can help me to update the facebook status using php easily?i shall be very much glud if anybody pls give any working solution. Regards---riad
Well, I've wrote a tutorial about posting to the user's wall: How To: Post A Message On The User Wall Using Facebook Graph API.
$args = array(
'message' => 'Hello from my App!',
'link' => 'http://www.masteringapi.com/',
'caption' => 'Visit MasteringAPI.com For Facebook API Tutorials!'
);
$post_id = $facebook->api("/me/feed", "post", $args);
Notes:
I'm using the PHP-SDK
You need the publish_stream permission
Check out this answer
What about checking directly the Facebook API ?
http://developers.facebook.com/docs/
Check the "Graph API"
The Graph API is the core of Facebook Platform, enabling you to read and write data to Facebook. It provides a simple and consistent view of the social graph, uniformly representing objects (like people, photos, events, and pages) and the connections between them (friendships, likes, and photo tags).
I wrote this code im my blog completely pl check that in the following link
http://scriptime.blogspot.in/2012/12/facebook-status-updates-using-php-sdk.html
here i am giving samll code
$status = $_POST['status'];
$facebook_id = $userdata['id'];
$params = array(
'access_token' => $access_token,
'message' => $status
);
$url = "https://graph.facebook.com/$facebook_id/feed";
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_POSTFIELDS => $params,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_VERBOSE => true
));

Categories