Facebook social plugin on android

被刻印的时光 ゝ 提交于 2019-12-22 18:29:08

问题


I would like to integrate Facebook's comment social plugin ( https://developers.facebook.com/docs/reference/plugins/comments/ to comment on url) into my android application. I tried to use webview (use this answer Android unable to implement facebook comment in a webview due to default browser ) and it's work, but hard to customize, for example: I want to have a bigger Textbox for user to type the comment. My question is: "is there any solution to integrate something like "Facebook's comment social plugin" into android application by facebook sdk, java code,... to comment on url?

Thanks & best regards


回答1:


As far as I understand you have some URL page where you've embedded your facebook social plugin with comments and you want to parse this and display as you want. If I'm right, then unfortunately I haven't found easy solution via triggering appropriated methods from Facebook SDK. You have to use Graph API.

First of all we need to take a look into docs - https://developers.facebook.com/docs/graph-api/reference/v2.3/object/comments

Here there is a example of call

/* make the API call */
new Request(
    session,
    "/{object-id}/comments",
    null,
    HttpMethod.GET,
    new Request.Callback() {
        public void onCompleted(Response response) {
            /* handle the result */
        }
    }
).executeAsync();

For getting {object_id} you need to send similar call to the Graph API, but for retrieving id:

  GET->  ?id=http%3A%2F%2Fwww.imdb.com%2Ftitle%2Ftt2015381%2F

And you will receive response which looks like

    {
  "og_object": {
    "id": "10150298925420108", 
    "description": "Directed by James Gunn.  With Chris Pratt, Vin Diesel, Bradley Cooper, Zoe Saldana. A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe.", 
    "title": "Guardians of the Galaxy (2014)", 
    "type": "video.movie", 
    "updated_time": "2015-05-15T14:52:46+0000", 
    "url": "http://www.imdb.com/title/tt2015381/"
  }, 
  "share": {
    "comment_count": 4, 
    "share_count": 91073
  }, 
  "id": "http://www.imdb.com/title/tt2015381/"
}

10150298925420108 is our object_id

So next query looks like GET -> 10150298925420108/comments and response

{
  "data": [
    {
      "id": "10150298925420108_10152457293990108", 
      "can_remove": false, 
      "created_time": "2014-10-28T18:12:15+0000", 
      "from": {
        "id": "1513986108857171", 
        "name": "ซอโซ่ สระอา ยอยัก"
      }, 
      "like_count": 2, 
      "message": "สนุกมากค่ะ", 
      "user_likes": false
    }, 
    {
      "id": "10150298925420108_10152457392770108", 
      "can_remove": false, 
      "created_time": "2014-10-28T19:20:28+0000", 
      "from": {
        "id": "302917246580502", 
        "name": "สมชาย โกทันธ์"
      }, 
      "like_count": 0, 
      "message": "สองดาวครับ\n", 
      "user_likes": false
    }, 
    {
      "id": "10150298925420108_10152461977130108", 
      "can_remove": false, 
      "created_time": "2014-10-31T11:57:10+0000", 
      "from": {
        "id": "472810482857795", 
        "name": "Surat Thaenphet"
      }, 
      "like_count": 0, 
      "message": "แต่ละเรื่องที่ลง สนุกมาก แต่ดูไม่จบ ดูสักพัก ก็ eror  ไม่รุ้เป็นเพราะอะไร", 
      "user_likes": false
    }
  ], 
  "paging": {
    "cursors": {
      "before": "Mw==", 
      "after": "MQ=="
    }
  }
}

To test all this requests and response before doing it in Android app - use Graph API explorer https://developers.facebook.com/tools/explorer/



来源:https://stackoverflow.com/questions/16570094/facebook-social-plugin-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!