1

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());

}
3
  • 2
    Try giving "Web", "read" access in AppManifest.xml file
    – Garima
    Nov 18 '14 at 6:10
  • @Garima Thanks. That did the trick. Can you please reply it as answer so that i can mark it correct. I changed the permission from "Site Collection" to "Web". Although, VS is still displaying the error after deployment. One thing i didn't understand is that y didn't it require this permission for context.get_web().get_currentUser().get_title(); Nov 18 '14 at 6:23
  • 2
    Sure.. It didn't require permission for current user as you (i.e. current user) are running the app and just fetching your details which dont need any special permission. But if you query user profile (using PeopleManager) then you'll need to give it read access
    – Garima
    Nov 18 '14 at 6:30
4

Try giving "Read" permission to "Web" in AppManifest.xml and it should work.

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.