2014-03-12 26 views
1

我是sap abap和sap crm和javascript的新手。我試圖讓Facebook的頁面流進入我的BSP應用程序。使用javascript從FB.api()獲取結果到abap中

<%@page language="abap" %> 
<%@extension name="htmlb" prefix="htmlb" %> 
<htmlb:content id    = "content" 
       design   = "design2003" 
       controlRendering = "sap" 
       rtlAutoSwitch = "true" > 
    <htmlb:page title="jQuery" > 
    <htmlb:form id  = "formBody" 
       method = "post" > 
     <script type="text/javascript" src="jquery-1.7.2.min.js" ></script> 
     <script> 
     function getPosts() { 
     FB.api('/8****5833028****/feed', 'get', { access_token : '7***5058***8**7|qJzB0*****VRC***YfE****wpk4' }, function(normalData) { 
      if (!normalData || normalData.error) { 
      alert('Error occured'); 
      } else { 
      alert(normalData.data[0].from.name); 
      $('<div class="result"></div>') 
      .append('<h3>' + normalData.data[0].from.name + '</h3>') 
      .append('<h3>' + normalData.data[0].message + '</h3>') 
      .appendTo('body'); 
      document.getElementById("gv_response").value = normalData; 
      } 
      }); 
     } 
     </script> 
     <div id="fb-root"></div> 
     <script> 
     window.fbAsyncInit = function() { 
      FB.init({ 
      appId : '7***5058***8**7', 
      status : true, // check login status 
      cookie : true, // enable cookies to allow the server to access the session 
      xfbml : true // parse XFBML 
      }); 
     }; 
     (function() { 
      var e = document.createElement('script'); 
      e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; 
      e.async = true; 
      document.getElementById('fb-root').appendChild(e); 
     }()); 
     </script> 
     <a href="#" id="postButton" onClick="getPosts()">Facebook</a> 
     <htmlb:inputField id  = "gv_response" 
         type = "string" 
         visible = "true" 
         size = "120" /> 
     <htmlb:button id  = "myButton11" 
        text = "onClick" 
        onClick = "getPosts" /> 
     <body> 
     <div class="result"></div> 
     </body> 
    </htmlb:form> 
    </htmlb:page> 
</htmlb:content> 

有了上面的代碼,我把所有的數據和我寫的Facebook塗鴉牆的種子頁面上的用戶名。我的access_token和連接是正確的。

這是我的問題,我如何將值傳遞給bsp應用程序的變量。
- 我應該解析JavaScript中的值,並只傳遞問值?
- 或者有可能把所有的值都放到bsp的變量中並在bsp應用中序列化?

注:我知道有一個abap函數可以序列化jsons。

回答

0

現在我選擇一種這樣的方式;我創建了所有可能的字段,我應該使用html(或htmlb)代碼,並且這些字段是隱藏的。使用JavaScript代碼,我將這些問題的值發送到這些字段中。每飼料樣品

領域:

<htmlb:inputField id = "fb_002_uname" /> 
<htmlb:inputField id = "fb_002_umssg" /> 
<htmlb:inputField id = "fb_002_ctime" /> 
<htmlb:inputField id = "fb_002_utime" /> 

Javascript代碼:

document.getElementById("fb_002_uname").value = normalData.data[1].from.name; 
document.getElementById("fb_002_umssg").value = normalData.data[1].message; 
document.getElementById("fb_002_ctime").value = normalData.data[1].created_time; 
document.getElementById("fb_002_utime").value = normalData.data[1].updated_time; 

而在ABAP:

request->get_form_fields(CHANGING fields = lt_data). 

像這樣我會得到所有的字段值。

爲什麼我選擇這種方式?

  • 因爲我無法從Facebook獲取json。

如果你知道如何從Facebook獲得json字符串,請幫助我,如果你可以與樣品。

謝謝。 U 012