I would like to develop a page to get the list data from SharePoint 2013(Office 365)

I try to get the data from REST API e.g.

String url="https://siteurl/_api/web/GetFolderByServerRelativeUrl('Photo')/files"
WebRequest request = WebRequest.Create(url);
request.Credentials = new NetworkCredential(username, password);
request.ContentType = "application/json; charset=UTF-8";
WebResponse response = request.GetResponse();
Stream stream = response.GetResponseStream();
System.IO.StreamReader streamReader = new System.IO.StreamReader(stream, Encoding.UTF8);
string strOut = streamReader.ReadToEnd();

It will return the 403 error.

After my finding, I think I'm missing the access token, and the access token should be get from the SharePoint apps.

Anyone can tell me how can I get the access token.?

Is it mean I should create high trust app first, and let the page to call the app to get the access token??

Please let me know if the logic is wrong.

  • are you trying to do an app on Sharepoint 2013? Mar 26 '14 at 8:49
  • No , I am trying to connect SharePoint 2013 data from normal html page , maybe aspx / php etc.
    – HateBear
    Mar 26 '14 at 9:51
  • Maybe you need to refer to the Request.aspx page that lives in Sharepoint otherwise you cannot get the data Mar 26 '14 at 10:02

Since you are using Managed code to access SharePoint Online via REST API, i would recommend you to utilize the SharePoint Server 2013 Client Components SDK. It comes with a SharePointOnlineCredentials class that is intended for authenticating the user in SPO.

How to make a web request to SPO

var username = "username@tenant.onmicrosoft.com";
var password = "password";
var webUrl = "https://tenant.sharepoint.com";
var query = "/_api/web/GetFolderByServerRelativeUrl('Shared Documents')/files?$filter=Name eq 'Order.docx'";

//Construct SPO credentials 
var securedPassword = new SecureString();
foreach (var c in password.ToCharArray()) securedPassword.AppendChar(c);
var credentials = new SharePointOnlineCredentials(username, securedPassword);
//Make a request with SPO credentials
var request = WebRequest.Create(webUrl + query);            
request.Credentials = credentials;
request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.