1
votes

I'm newbie on sap abap and sap crm and javascript. I'm trying to get facebook's page stream into my bsp app.

<%@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>

With above code, i took all data and i write user name on page from facebook wall's feed. My access_token and connection is right.

Here's my question, how can i pass value into bsp app.'s variable.
- should i parse value in javascript and pass only asked value's?
- or is that possible take all value into bsp's variable and serialize in bsp app?

note: i know there's an abap function can serialize jsons.

1

1 Answers

0
votes

For now i choose a way like this; I created all possible field i should use with html(or htmlb) code and those fields were hidden. With javascript code, i give my asked value into those fields.

Fields per feed sample:

<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 code:

 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;

And in abap:

request->get_form_fields( CHANGING fields = lt_data ).

like these i'll get all fields value.

Why i choose like this way?

  • Because i couldn't get json from facebook.

If you know how can i get json string from facebook, please help me and if you can with sample.

Thank you. Utku