Skip to Content
Author's profile photo Former Member

Using YouTube API inside a BSP application

Try this five minutes tutorial to get YouTube capabilities inside your ABAP stack.   Before to put hands on your ABAP environment, get your developer id in YouTube. ( http://www.youtube.com/dev  (http://www.youtube.com/dev) ).    *TUTORIAL*    *1.* Create these entities in data dictionary.  image *2.* Create a bsp application (proposed name ZYOUTUBE), with a page with flow logic (proposed name ZYOUTUBE.htm) and set the status (in Properties tab ) “Stateful from now On. Lifetime : Session”.    *3.* Set attributes to page  image *4.* Page Layout.*5.* OnInputProcessing event handler code.* event handler for checking and processing user input and * for defining navigation  *GENERAL   data: event type ref to cl_htmlb_event.   event = cl_htmlb_manager=>get_event( runtime->server->request ).  * SEARCH EVENT   if event->id = ‘B_SRCH’.      clear wa_sel_video.  *   HTTP POST     data: url type string.     data: urlrest type string.     data: devid type string.     data: searchvalue type string.      data: http_client type ref to if_http_client .     data: response type string.      data: cl_description type ref to cl_htmlb_inputfield.      cl_description ?= cl_htmlb_manager=>get_data(                     request = runtime->server->request                     name    = ‘inputField’                     id    = ‘search’).      searchvalue = cl_description->value.      urlrest = ‘http://www.youtube.com/api2_rest?method=youtube.videos.list_by_tag‘.      devid = ‘get_cdata( ).    *   XML PARSER     class cl_ixml definition load.     data : ixml          type ref to if_ixml,           g_ixml        type ref to if_ixml,           streamfactory type ref to if_ixml_stream_factory,           istream       type ref to if_ixml_istream,           document      type ref to if_ixml_document,           element       type ref to if_ixml_element,           encoding      type ref to if_ixml_encoding,           parser        type ref to if_ixml_parser,           child         type ref to if_ixml_node,           child1        type ref to if_ixml_node,           child2        type ref to if_ixml_node,           name          type string,           valor         type string.       if not response is initial.        g_ixml = cl_ixml=>create( ).       ixml = cl_ixml=>create( ).       streamfactory = ixml->create_stream_factory( ).       istream  = streamfactory->create_istream_cstring( response ).       document = ixml->create_document( ).        encoding = g_ixml->create_encoding(                     character_set = ‘utf-8’                     byte_order = 0 ).       document->set_encoding( encoding = encoding ).        parser   = ixml->create_parser( stream_factory  = streamfactory                                        istream         = istream                                        document        = document ).       parser->set_normalizing( ).       parser->set_validating( mode = if_ixml_parser=>co_no_validation ).        if parser->parse( ) ne 0.         write ‘parser Error’.       endif.  *     XML TO TABLE       data: nodes type ref to if_ixml_node_list,             nodes1 type ref to if_ixml_node_list,             nodes2 type ref to if_ixml_node_list,             index type i,             index1 type i,             index2 type i.        data: wa_video type zvideo.        element = document->get_root_element( ).       nodes = element->get_children( ).        clear it_videos.        while index<nodes->get_length( ) .          child = nodes->get_item( index ).         valor  = child->get_value( ).         name   = child->get_name( ).         index = index + 1.          index1 = 0.         nodes1 = child->get_children( ).          while index1<nodes1->get_length( ).            child1 = nodes1->get_item( index1 ).           valor  = child1->get_value( ).           name   = child1->get_name( ).           index1 = index1 + 1.            if name eq ‘video’.              index2 = 0.             nodes2 = child1->get_children( ).              clear wa_video.              while index2<nodes2->get_length( ).                child2 = nodes2->get_item( index2 ).               valor  = child2->get_value( ).               name   = child2->get_name( ).               index2 = index2 + 1.                case name.                 when ‘author’. wa_video-author = valor.                 when ‘id’. wa_video-id = valor.                 when ‘title’. wa_video-title = valor.                 when ‘length_seconds’. wa_video-length_seconds = valor.                 when ‘rating_avg’. wa_video-rating_avg = valor.                 when ‘rating_count’. wa_video-rating_count = valor.                 when ‘description’. wa_video-description = valor.                 when ‘view_count’. wa_video-view_count = valor.                 when ‘upload_time’. wa_video-upload_time = valor.                 when ‘comment_count’. wa_video-comment_count = valor.                 when ‘tags’. wa_video-tags = valor.                 when ‘url’. wa_video-url = valor.                 when ‘thumbnail_url’. wa_video-thumbnail_url = valor.                 when ’embed_status’. wa_video-embed_status = valor.               endcase.              endwhile.              append wa_video to it_videos.            endif.          endwhile.        endwhile.      endif.    endif.  * VIEW VIDEO EVENT   if event->id = ‘table’.      data: tv type ref to cl_htmlb_tableview.      tv ?= cl_htmlb_manager=>get_data(                             request      = runtime->server->request                             name         = ‘tableView’                             id           = ‘table’ ).      if tv is not initial.       if tv->data->selectedrowindex is not initial.         read table it_videos index tv->data->selectedrowindex into wa_sel_video.       endif.     endif.    endif.    You can now begin to search and watch videos. image

Assigned Tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member
      Hi Ignacio:

      Really nice blog -:D Doesn't have the chance to test it (At least not with my MiniSAP 4.6D but your pics are enough for me -;)

      Keep on the good work! -:D

      Greetings,

      Blag.

      Author's profile photo Former Member
      Former Member
      Blog Post Author
      Gracias Alvaro, espero estar pronto en Lima para comer un ceviche juntos ( obviamente con abundante cerveza e IncaCola ) un afectuoso saludo a ti y todo el Perú.

      English Version: Thanks Alvaro, I wait to be soon in Lima, eating together ceviche with beer and of course IncaCola, Regards to you and all Perú.

      Author's profile photo Former Member
      Former Member
      Ignacio:

      I would be awesome to arrange and meeting and have something to eat -:) Just write me an e-mail when your planning to come Perú, so we can chat and schedule the meeting -:D

      Greetings,

      Blag.

      Author's profile photo Raja Thangamani
      Raja Thangamani
      Good one..Keep it up...Also please add it in BSP blog forum, so that it will be notified to all who has watch on this...

      Raja T