Options

Collecting Comments from an FB Post using RapidMiner

WineWine Member Posts: 19 Maven
edited April 2022 in Help
Hello RapidMiner Community,

I wonder if there's a way for us to collect comments from an FB post using RapidMiner? Hope someone can help me with this.

Thanks,
Wine

Best Answers

  • Options
    jwpfaujwpfau Employee, Member Posts: 280 RM Engineering
    edited April 2022 Solution Accepted
    Hi Wine,

    you can just use the facebook graph API together with the GET (REST) and the JSON to Data operator from the Web Extension.

    The url would be something like this

    https://graph.facebook.com/v13.0/%{comment-id}/comments?access_token=%{access-token}&debug=all&fields=id%2Cmessage&format=json&method=get&pretty=0&suppress_http_code=1&transport=cors

    You can use the Set Macros operator to set the comment-id and the access-token.

    See https://developers.facebook.com/docs/graph-api/reference/v13.0/comment for more details.

    You might need to verify yourself to facebook to use this api.

    https://developers.facebook.com/docs/permissions/reference/pages_read_engagement/

    Greetings,
    Jonas 


  • Options
    jwpfaujwpfau Employee, Member Posts: 280 RM Engineering
    Solution Accepted
    Hi Wine,

    great to hear that you got it to work.

    Here is at least a super complicated way to do it that i found in another  thread https://community.rapidminer.com/discussion/comment/23738/
    <?xml version="1.0" encoding="UTF-8"?><process version="9.10.007">
      <context>
        <input/>
        <output/>
        <macros/>
      </context>
      <operator activated="true" class="process" compatibility="9.10.007" expanded="true" name="Process">
        <parameter key="logverbosity" value="init"/>
        <parameter key="random_seed" value="2001"/>
        <parameter key="send_mail" value="never"/>
        <parameter key="notification_email" value=""/>
        <parameter key="process_duration_for_mail" value="30"/>
        <parameter key="encoding" value="SYSTEM"/>
        <process expanded="true">
          <operator activated="true" class="text:create_document" compatibility="9.4.000" expanded="true" height="68" name="Create Document" width="90" x="45" y="34">
            <parameter key="text" value="{&quot;data&quot;: [&#10;  {&#10;    &quot;color&quot;: &quot;purple&quot;,&#10;    &quot;type&quot;: &quot;minivan&quot;,&#10;    &quot;capacity&quot;: &quot;7&quot;&#10;  },&#10;  {&#10;    &quot;color&quot;: &quot;red&quot;,&#10;    &quot;type&quot;: &quot;station wagon&quot;,&#10;    &quot;capacity&quot;: &quot;5&quot;&#10;  }&#10;]}"/>
            <parameter key="add label" value="false"/>
            <parameter key="label_type" value="nominal"/>
          </operator>
          <operator activated="true" class="web:json_to_xml" compatibility="9.7.000" expanded="true" height="68" name="JSON to XML" width="90" x="179" y="34">
            <parameter key="enclosing_tag_name" value="json"/>
          </operator>
          <operator activated="true" class="text:write_document" compatibility="9.4.000" expanded="true" height="82" name="Write Document" width="90" x="313" y="34">
            <parameter key="overwrite" value="true"/>
            <parameter key="encoding" value="SYSTEM"/>
          </operator>
          <operator activated="true" class="advanced_file_connectors:read_xml" compatibility="9.10.007" expanded="true" height="68" name="Read XML" width="90" x="447" y="34">
            <parameter key="file" value=""/>
            <parameter key="xpath_for_examples" value="//json/data"/>
            <enumeration key="xpaths_for_attributes">
              <parameter key="xpath_for_attribute" value="color[1]/text()"/>
              <parameter key="xpath_for_attribute" value="type[1]/text()"/>
              <parameter key="xpath_for_attribute" value="capacity[1]/text()"/>
            </enumeration>
            <parameter key="use_namespaces" value="true"/>
            <list key="namespaces"/>
            <parameter key="use_default_namespace" value="false"/>
            <parameter key="parse_numbers" value="true"/>
            <parameter key="decimal_character" value="."/>
            <parameter key="grouped_digits" value="false"/>
            <parameter key="grouping_character" value=","/>
            <parameter key="infinity_representation" value=""/>
            <parameter key="date_format" value=""/>
            <list key="annotations"/>
            <parameter key="time_zone" value="SYSTEM"/>
            <parameter key="locale" value="English (United States)"/>
            <parameter key="read_all_values_as_polynominal" value="false"/>
            <list key="data_set_meta_data_information"/>
            <parameter key="read_not_matching_values_as_missings" value="true"/>
            <parameter key="datamanagement" value="double_array"/>
            <parameter key="data_management" value="auto"/>
          </operator>
          <operator activated="true" class="rename_by_replacing" compatibility="9.10.007" expanded="true" height="82" name="Rename by Replacing" width="90" x="581" y="34">
            <parameter key="attribute_filter_type" value="all"/>
            <parameter key="attribute" value=""/>
            <parameter key="attributes" value=""/>
            <parameter key="use_except_expression" value="false"/>
            <parameter key="value_type" value="attribute_value"/>
            <parameter key="use_value_type_exception" value="false"/>
            <parameter key="except_value_type" value="time"/>
            <parameter key="block_type" value="attribute_block"/>
            <parameter key="use_block_type_exception" value="false"/>
            <parameter key="except_block_type" value="value_matrix_row_start"/>
            <parameter key="invert_selection" value="false"/>
            <parameter key="include_special_attributes" value="false"/>
            <parameter key="replace_what" value="\[.*"/>
            <parameter key="replace_by" value=""/>
          </operator>
          <connect from_op="Create Document" from_port="output" to_op="JSON to XML" to_port="document"/>
          <connect from_op="JSON to XML" from_port="document" to_op="Write Document" to_port="document"/>
          <connect from_op="Write Document" from_port="file" to_op="Read XML" to_port="file"/>
          <connect from_op="Read XML" from_port="output" to_op="Rename by Replacing" to_port="example set input"/>
          <connect from_op="Rename by Replacing" from_port="example set output" to_port="result 1"/>
          <portSpacing port="source_input 1" spacing="0"/>
          <portSpacing port="sink_result 1" spacing="0"/>
          <portSpacing port="sink_result 2" spacing="0"/>
        </process>
      </operator>
    </process>
    

    Greetings,
    Jonas

Answers

  • Options
    WineWine Member Posts: 19 Maven
    Thanks so much, Jonas. This is immensely helpful. I'm trying this out. 
  • Options
    WineWine Member Posts: 19 Maven
    Hello Jonas,

    Thanks for this. I followed your instructions. I was able to get both comment ID and access token from FB and placed it in the "set macros" operator:



    Then I placed the url you sent in the get(rest) operator:

    https://graph.facebook.com/v13.0/%{comment-id}/comments?access_token=%{access-token}&debug=all&fields=id%2Cmessage&format=json&method=get&pretty=0&suppress_http_code=1&transport=cors





    However, I get an error when running:



    I get this despite putting the macros in the set macros. Not sure what I did wrong. Hope you can enlighten me with this one. Thanks so much for replying and helping.

    Warm regards from the Philippines,
    Wine
  • Options
    WineWine Member Posts: 19 Maven
    Wohoo! I was able to make it work :-) This is a really big help. My next issue it to fix the table. I wonder how I can fix this into columns. Thanks so much, Jonas! :-)




  • Options
    WineWine Member Posts: 19 Maven
    Super big thanks! Jonas 😄 I’ll employ that too for the table. What I initially did was to fix the output using excel. Many many thanks. 
Sign In or Register to comment.