How to Login and get authorization code with OneDrive API using PHP

How to Login and get authorization code with OneDrive API using PHP

In this post we will show you how to Log in and get authorization code(also with office 365 authorization) with OneDrive API using PHP. After completed process of “Registering your app for OneDrive API” you need add this code in php file.

In this following code you have to pass CLIENT ID , CLIENT SECRET and REDIRECT URL. By passing this detail, this code it will return authorization code of OneDrive api.

// ADD YOUR CLIENT ID
$client_id     = "ADD-YOUR-CLIENT-ID";
// ADD YOUR CLIENT SECRET
$client_secret = "ADD-YOUR-CLIENT-SECRET";
// ADD REDIRECT URL
$redirect_uri  = "HTTPS://YOUR-DOMIN.COM/FOLDER-NAME/index.php";
 
echo "<h1>office 365 api test</h1>";
$_response = "https://login.microsoftonline.com/common/oauth2/authorize?client_id=".$client_id."&scope=wl.signin%20wl.offline_access%20wl.skydrive_update%20wl.basic&response_type=code&redirect_uri=".urlencode($redirect_uri);	

if(!isset($_GET['code'])) 
{
	// you need to login hear to get code and token
	// Log-in and get an _authorization code
	echo "<h2>LOGIN</h2>";
	echo "<span style='vertical-align: middle;'><a href='".$_response."'>Login Hear</a></span>";
}
else 
{	
	//  get _authorization code
	// get code usnig $_GET method 
	$_authorization = $_GET['code'];
	// print _authorization code
	echo $_authorization;
}

SEE MORE :
office 365 token – How to get token in office 365 using PHP?

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  76  =  80

We accept paid advance and paid guest Posting on our Site : Contact US