2014-04-19 85 views
1

已更新。無法保存變量中保存的數據 - 沒有方法「設置」

此代碼塊將用戶臉書連接並將其保存到「fbdata」和div「friends-list-container」中。

以下是出現錯誤的頁面。

然後,我試圖將數據保存到parse.com,並在下面顯示了以下錯誤消息。

<!doctype html> 

    <!-- Runs Parse and FB code that uses Facebook authentication to login 
user to the site and redirects them to the main content area. This page is 
fired from the Facebook button being clicked on the site landing page--> 


     <html lang="en"> 
     <head> 
      <meta charset="utf-8"> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <meta name="description" content="fresh Gray Bootstrap 3.0 Responsive Theme "/> 
      <meta name="keywords" content="Template, Theme, web, html5, css3, Bootstrap,Bootstrap 3.0 Responsive Login" /> 
      <meta name="author" content="Adsays"/> 
      <title>Parse JavaScript Todo App</title> 
      <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script> 
      <script src="scripts/underscore-1.1.6.js"></script> 
      <script src="http://www.parsecdn.com/js/parse-1.2.13.min.js"></script> 



     </head> 
     <body> 

      <!-- Important, must be on the page --> 
      <div id="fb-root"></div>  


      <!-- Initialize the Parse object--> 
      <script type="text/javascript">  
      Parse.initialize("79tphN5KrDXdjJnAmehgBHgOjgE2dLGTvEPR9pEJ", "9lblofQNZlypAtveU4i4IzEpaOqtBgMcmuU1AE6Y"); 

      var user = Parse.User.current(); 
     //Fb app information// 

     window.fbAsyncInit = function() { 
      Parse.FacebookUtils.init({ 
       appId  : '523753101076577', 
       channelUrl : 'http://www.kudosoo.com/channel.html', 
       status  : true, 
       cookie  : true, 
       xfbml  : true 
      }); 

     //FB user authentication script, after this completes it fires todos_two.js to redirect user to main content page// 


     FB.getLoginStatus(function (response) { 
      if (response.status === 'connected') { 
      FB.api('/me/friends', function(response){ 
       if (response && response.data){ 
       var contact = new Parse.User(); 
       var fbdata=response.data; 
       var divTarget=document.getElementById("friends-list-container"); 
       for (var friendIndex=0; friendIndex<fbdata.length; friendIndex++) 
      {  var divContainer = document.createElement("div"); 
        divContainer.innerHTML="<b>" + fbdata[friendIndex].name + "</b>"; 
        divTarget.appendChild(divContainer); 
      } 

     var contact = new Parse.User(); 
     var contact = new Contact(); 



      $(document).ready(function() { 
         var username = $("#friends-list-container").val(); 
         contact.set("facebookFriends", fbdata.toString()); 
         contact.save(null, { 
          success: function (results) { 
           // The object was saved successfully. 
           location.reload(); 
          }, 
          error: function (contact, error) { 
           // The save failed. 
           // error is a Parse.Error with an error code and description. 
            alert("Error: " + error.code + " " + error.message); 
          } 
         }); 
        }); 


       } else { 
       console.log('Something goes wrong', response); 
       } 
      }); 

      } 
     }); 



     }; 

     (function(d, s, id){ 
      var js, fjs = d.getElementsByTagName(s)[0]; 
      if (d.getElementById(id)) {return;} 
      js = d.createElement(s); js.id = id; 
      js.src = "//connect.facebook.net/en_US/all.js"; 
      fjs.parentNode.insertBefore(js, fjs); 
     }(document, 'script', 'facebook-jssdk')); 


     </script> 
     <div id="friends-list-container"></div> 
     </body> 
     </html> 

這是錯誤。 enter image description here

enter image description here

+0

難道'contact'沒有'set'方法嗎? – Hatsjoem

+0

@Hatsjoem不確定關注?這是不是在這裏做? contact.set(「facebookFriends」,fbdata.toString());你可以給我一個例子嗎? – Dano007

+0

看看錯誤,聯繫人沒有設置方法「對象聯繫人沒有方法設置」 – Hatsjoem

回答

1

嘗試更換這行:

var contact = Parse.Object.extend("_User"); 

從聊天對話更新,這就是解決了這個問題:如果你想存儲在好友列表中

array當前用戶,然後Parse.User.current()是你想要的:

var contact = Parse.User.current() 
+0

謝謝,我很接近......我很高興接受這個答案,如果我現在就可以解決這個問題。該頁面在開發工具中返回POST https://api.parse.com/1/users 400(錯誤請求)錯誤。實際頁面在這裏http://kudosoo.com/addfriends.html我不知道爲什麼它要求輸入密碼,因爲用戶已經登錄了? – Dano007

+0

我不習慣JS API for Parse,但經過一番檢查後,似乎User類在這裏也是特別的。檢查這個鏈接:https://parse.com/questions/extending-the-default-parse-user – Moonwalkr

+0

在你的使用中,我評論過的部分,似乎並不需要像這樣擴展User類。你只是想用它做普通的東西。我會編輯我的答案,以我認爲你需要做的事情。 – Moonwalkr