I have created a SharePoint App for my Office 365 Developer site. The app is throwing an error when trying to access the Site's url.
var context = SP.ClientContext.get_current();
var web = context.get_web();
context.load(web);
context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);
function onGetUserNameSuccess() {
$('#message').text(web.get_url());
}
Error - Access denied. You do not have permission to perform this action or access this resource.
However, when i am accessing the site's user, the code is running fine.
var context = SP.ClientContext.get_current();
var user = context.get_web().get_currentUser();
context.load(user);
context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);
function onGetUserNameSuccess() {
$('#message').text('Hello ' + user.get_title());
}