Getting user data (REST)

Your app can get user data on Microsoft OneDrive, by using the Live SDK REST API.

In this article
Prerequisites
Step 1: Requesting info
Step 2: Requesting info about the user's friends
Step 3: Working with info

To access a user's info from Microsoft OneDrive, and other services that are compatible with Microsoft account, your app must check for two things. First, it must confirm that the user has signed in successfully. Second, it must request and receive the user's consent, to work with his or her info. For details about these steps, see Signing users in with REST and Obtaining user consent using REST.

Prerequisites

This topic assumes that your app has initialized the Live SDK successfully, the user has signed in successfully, and the user has consented to the wl.basic scope, which grants access to basic info about the user and his or her contacts.

Step 1: Requesting info

There are two different ways to work with a user's info.

  • The user ID of a person or contact.

  • The me shortcut that provides access to the signed-in user.

This code example shows how to request info about a specific person identified by the user ID, which is represented in this code example as USER_ID. In your code, replace USER_ID with the actual ID string of the user or contact for which you want to get info and ACCESS_TOKEN with the access token provided when the user signed in.

GET https://apis.live.net/v5.0/USER_ID?access_token=ACCESS_TOKEN

This code example shows how to use the me shortcut to request info about the signed-in user. In your code, replace ACCESS_TOKEN with the access token provided when the user signed in.

GET https://apis.live.net/v5.0/me?access_token=ACCESS_TOKEN

Step 2: Requesting info about the user's friends

This code example shows how to use the me shortcut to get a list of the signed-in user's friends. In your code, replace ACCESS_TOKEN with the access token provided when the user signed in.

GET https://apis.live.net/v5.0/me/friends?access_token=ACCESS_TOKEN

Assuming that your app has permission to access data about the user's friends, you can get that info by using the user ID of a particular friend. In this example, the contact string shown was in the response returned by the preceding example. In your code, you would use a value returned by the preceding call and not the contact string shown in this example. Also, in your code, replace ACCESS_TOKEN with the access token provided when the user signed in.

GET https://apis.live.net/v5.0/contact.c1678ab4000000000000000000000000?access_token=ACCESS_TOKEN
 

In REST, after you make the appropriate GET call, the first name of the user's friend's is in the response. Here's how to make a call by using the friend's ID. In this example, the contact string shown was in the response returned by the example above. In your code, you would use a value returned in your app and not the contact string shown in this example. Also, in your code, replace ACCESS_TOKEN with the access token provided when the user signed in.

GET https://apis.live.net/v5.0/contact.c1678ab4000000000000000000000000?access_token=ACCESS_TOKEN

Step 3: Working with info

To make an HTTP GET call to the Live SDK REST API to get user info, use the following URL and replace these placeholders:

  • Replace REST_PATH with the REST path to the portion of the user's info that you want for example, me.

  • Replace ACCESS_TOKEN with your access token.

https://apis.live.net/v5.0/REST_PATH?access_token=ACCESS_TOKEN

For example, the following URL uses a REST path of me, and an access token that starts with the characters "EwCo" and ends with the characters "AA==".

https://apis.live.net/v5.0/me?access_token=EwCo...//access token string shortened for example//...AA==

If the HTTP GET call is successful, the Live SDK returns the response as info formatted in JavaScript Object Notation (JSON). Here's a JSON-formatted object that contains a user's publicly available info.

{
  "id" : "contact.c1678ab4000000000000000000000000",
  "first_name" : "Roberto",
  "last_name" : "Tamburello",
  "name" : "Roberto Tamburello",
  "gender" : "male",
  "locale" : "en_US"
}