PHP Connect sample using Microsoft Graph
Connecting to Microsoft Graph is the first step every app must take to start working with Office 365 services and data. This sample shows how to connect and then call one API through Microsoft Graph and uses the Office Fabric UI to create an Office 365 experience.
Try out the Microsoft Graph Quick Start page which simplifies registration so you can get this sample running faster.
Note: For an in-depth look at the code, see Call Microsoft Graph in a PHP app.
To use the PHP Connect sample, you need the following:
- PHP is required to run the sample on a development server. The instructions in this sample use the PHP 5.4 built-in web server. However, the sample has also been tested on Internet Information Services and Apache Server.
- Client URL (cURL) module. The web application uses cURL to issue requests to REST endpoints.
- Composer, dependency manager for PHP
Register and configure the app
- Sign into the App Registration Portal using either your personal or work or school account.
- Select Add an app.
Enter a name for the app, and select Create application.
The registration page displays, listing the properties of your app.
Under Platforms, select Add platform.
- Select Web.
Add the following to the list of Redirect URIs:
Under Application Secrets click Generate New Password.
- Copy the New password generated and Application Id, you'll need them in the next section.
- Click Save.
Configure and run the app
- Using your favorite IDE, open Constants.php in the src folder.
- Replace ENTER_YOUR_CLIENT_ID with the application id from the previous section.
- Replace ENTER_YOUR_SECRET with the password from the previous section.
Install the dependencies with the following command:
Start the built-in web server with the following command:
php -S 0.0.0.0:8000 -t app
http://localhost:8000in your web browser.
Error: Unable to get local issuer certificate
You receive the following error after providing your credentials to the sign in page.
SSL certificate problem: unable to get local issuer certificate
cURL can't verify the validity of the Microsoft certificate when trying to issue a request call to get tokens. You must configure cURL to use a certificate when issuing https requests by following these steps:
- Download the cacert.pem file from cURL website.
- In Chrome, right-click the cacert.pem link and choose Save link as.
- In Microsoft Edge, right-click the cacert.pem link and choose Save target as. Then rename the saved file's htm extension to pem.
Open your php.ini file and add the following line:
curl.cainfo = "absolute_path_to_cacert/cacert.pem"
Restart the server.
If you'd like to contribute to this sample, see CONTRIBUTING.MD.
Questions and comments
We'd love to get your feedback about the PHP Connect sample. You can send your questions and suggestions to us in the Issues section of this repository.
Questions about Microsoft Graph development in general should be posted to Stack Overflow. Make sure that your questions or comments are tagged with [MicrosoftGraph] and [API].
Copyright (c) 2016 Microsoft. All rights reserved.