使用javascript从FB.api()获取结果到abap

Getting result from FB.api() into abap with javascript

本文关键字:获取 结果 abap javascript FB api 使用      更新时间:2023-09-26

我是sap abap和sap crm和javascript的新手。我想让facebook的页面流到我的bsp应用程序。

<%@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墙的feed页面上写用户名。我的access_token和连接是正确的。

这是我的问题,我怎么能传递值到bsp应用程序的变量。
-我应该在javascript中解析值,只传递问值吗?
-或者是可能采取所有值到bsp的变量和bsp应用程序序列化?

注意:我知道有一个abap函数可以序列化json。

现在我选择这样的方式;我创建了所有可能的字段,我应该使用html(或htmlb)代码和这些字段是隐藏的。使用javascript代码,我将我的请求值输入这些字段。

每个feed样本的字段:

<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字符串,请帮助我,如果你可以与样本。

谢谢。Utku