0

I am trying to create an SharePoint hosted app that contains an app part, this app part should show what the user is following. I have used working code as an example in the app, but I don't get it to work inside of the App Part.

I get this within the app part: "Uncaught ReferenceError: _spPageContextInfo is not defined".

If anyone has a real example how to make this work inside an app part, and using social.following, please help!

This is the code in App.js:

    var headline = new Array("People", "Documents", "Sites");
    var ActorImg = new Array("/_layouts/15/images/person.gif", "/_layouts/15/images/lg_ICGEN.gif",         "/_layouts/15/images/siteicon_16x16.png");

function doJSON(RESTuri, success, fail) {
    var restUrl = _spPageContextInfo.webAbsoluteUrl + RESTuri;
    var executor = new SP.RequestExecutor(_spPageContextInfo.webAbsoluteUrl);
    executor.executeAsync(
    {
        url: restUrl,
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: success,
        error: fail
    }
    );
}


function renderSuccess(data) {
    var jsonObject = JSON.parse(data.body);
    var n = document.getElementById('jsonout');
    n.innerHTML = data.body;
    var results = jsonObject.d.Followed.results;
    var str = '';
    var old = -1;
    var img = null;

    for (j = 0; j < 5; j++) {
        str += "<div class=\"container container" + j + "\">";
        for (i = 0; i < results.length; i++) {
            if (j != results[i].ActorType) continue;
            if (old != results[i].ActorType) str += "<h1 class=\"headline" + results[i].ActorType + "\">" + headline[results[i].ActorType] + "</h1>";

            img = results[i].ImageUri;
            if (img == null) img = ActorImg[results[i].ActorType];

            switch (results[i].ActorType) {
                case 0:
                    // Use case: depending on ActorType if you want to use indiviual markup for every item-type
                    str += "<a title=\"" + results[i].Name + "\" class=\"link" + results[i].ActorType + "\" style=\"background-image:url(" + img + ")\" href=\"" + results[i].Uri + "\">" + results[i].Name + "</a>";
                    break;
                default:
                    str += "<a title=\"" + results[i].Name + "\" class=\"link" + results[i].ActorType + "\" style=\"background-image:url(" + img + ")\" href=\"" + results[i].Uri + "\">" + results[i].Name + "</a>";
                    break;
            }

            old = results[i].ActorType;
        }
        str += "</div>";
    }

    n = document.getElementById('htmlout');
    n.innerHTML = str + "<h1></h1>";
}

function renderFail(data, errorCode, errorMessage) {
    n = document.getElementById('htmlout');
    n.innerHTML = errorMessage;
}

$(document).ready(function () {


    doJSON("/_api/social.following/my/followed%28types=15%29", renderSuccess, renderFail);
});

This is the div that's being used in both the app page(default.aspx) and the app part page(AppPart.aspx):

<div class="classic">
        <pre id="jsonout" style="display: none;"></pre>
        <div id="htmlout"></div>
</div> 

1 Answers1

0

Sorry guys. I solved it by just adding a reference to the sp.requestexecutor.js file, and parsed the host- and app-url from the querystring