1

I am currently trying hard to apply this code. I was aiming to implement following site and other operations:

         // Replace the siteUrl placeholder value before you run the code.
         var siteUrl = "https://uling.sharepoint.com/site1";
         var followingManagerEndpoint;

         // Get the SPAppWebUrl parameter from the query string and build
         // the Following manager endpoint.
         $(document).ready(function () {
             var appweburl;
             var params = document.URL.split("?")[1].split("&");
             for (var i = 0; i < params.length; i = i + 1) {
                 var param = params[i].split("=");
                 if (param[0] === "SPAppWebUrl") appweburl = param[1];
             }
             followingManagerEndpoint = decodeURIComponent(appweburl) + "/_api/social.following";
             isFollowed();
         });

         // Check whether the current user is already following the site.
         // The request body includes a SocialActorInfo object that represents
         // the specified item. 
         // The success function reads the response from the REST service and then
         // toggles the user's following status by calling the appropriate method.
         function isFollowed() {

             console.log(d+" :: "+ followingManagerEndpoint);

             $.ajax({
                 url: followingManagerEndpoint + "/isfollowed",
                 type: "POST",
                 data: JSON.stringify({
                     "actor": {
                         "__metadata": {
                             "type": "SP.Social.SocialActorInfo"
                         },
                         "ActorType": 2,
                         "ContentUri": siteUrl,
                         "Id": null
                     }
                 }),
                 headers: {
                     "accept": "application/json;odata=verbose",
                     "content-type": "application/json;odata=verbose",
                     "X-RequestDigest": d
                 },
                 success: function (responseData) {

                     stringData = JSON.stringify(responseData);
                     jsonObject = JSON.parse(stringData);
                     if (jsonObject.d.IsFollowed === true) {
                         alert('The user is currently following the site.');
                         stopFollowSite();
                     }
                     else {
                         alert('The user is currently NOT following the site.');
                         followSite();
                     }
                 },
                 error: requestFailed
             });
         }

At first Ii got the error :

Uncaught TypeError: Cannot read property 'IsFollowed' of undefined

So I tried to view what's the content on the responsedata but it returns this :

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" data-ng-app="myapp">
    <head>
        <title>My App</title>
        <script type="text/javascript" src="../Scripts/jquery-1.9.1.min.js"></script>
        <script type="text/javascript" src="../Scripts/bootstrap.min.js"></script>
        <script type="text/javascript" src="../Scripts/angular.min.js"></script>
        <script type="text/javascript" src="../Scripts/angular-route.js"></script>
        <script type="text/javascript" src="../Scripts/alphaKanban.js"></script>
        <script type="text/javascript" src="../Scripts/Controllers.js"></script>
        <link href="../Content/bootstrap.min.css" rel="stylesheet" />
        <link href="../Content/bootstrap-theme.min.css" rel="stylesheet" />
    </head>
    <body>
        <div class="well">
            <div class="row">
                <div class="col-md-12">
                    <h1>My App</h1>
                </div>
            </div>
            <div data-ng-view></div>
        </div>
    </body>
</html>

Which are the elements in my html file. What is the problem? Did I miss anything?

3
  • where are you writing the code?
    – Taran Goel
    Sep 10, 2015 at 4:29
  • im building the app with angular js basically it's from my index.aspx and the codes are on the controller.js
    – Looytawon
    Sep 10, 2015 at 5:13
  • Are you using cross-site context calls They are required in SharePoint hosted apps. Check out this: sharepoint.stackexchange.com/questions/83135/… Sep 10, 2015 at 7:53

0

Your Answer

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

Browse other questions tagged or ask your own question.