I have a problem in connecting to SharePoint online from the Windows 8.1 Application.
My goal is quite simple:
Connect to SharePoint
Retrieve the List of Lists
Get Items from a List
I have tried many and many way but I receive always the same "answer": 403 FORBIDDEN.
I'm Administrator on the SharePoint online Site Collection.
Here 2 examples of my code:
A) Trying to take the Auth Token
HttpClient hc = new HttpClient(new HttpClientHandler()
{
Credentials = new NetworkCredential("user@domain", "password"),
});
hc.PostAsync(SharePointSite + "_api/contextinfo", new FormUrlEncodedContent(new List<KeyValuePair<string,string>>())).ContinueWith(
postTask =>
{
var cnt = postTask.Result.Content;
digest = cnt.ToString(); //FORBIDDEN!
allDone.Set();
});
allDone.WaitOne();
return digest;
B) Trying to access direct to the content
System.Net.Http.HttpClient _Client = new System.Net.Http.HttpClient(new HttpClientHandler()
{
Credentials = new NetworkCredential(Username, Password, Domain),
});
_Client.BaseAddress = new Uri(SharePointSite);
_Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(@"application/atom+xml"));
//_Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _FormatBasicAuth(Domain, Username, Password));
HttpResponseMessage resp = _Client.GetAsync(SharePointSite + "_api/web/lists").Result;
string respString = resp.Content.ReadAsStringAsync().Result;
if (resp.StatusCode==HttpStatusCode.OK){
}
I read a lot, these are some interesting link
http://msdn.microsoft.com/en-us/library/office/jj164022(v=office.15).aspx