Identifying Facebook Messenger user with UserID from a Facebook Login

前端 未结 5 1878
逝去的感伤
逝去的感伤 2021-01-30 09:27

I am trying out the new Facebook Messenger Platform and have hit a bit of a problem.

When a user first chats with my Bot, I want to use the sender.id to loo

相关标签:
5条回答
  • 2021-01-30 09:35

    Facebook's latest update includes a new "Account Linking" functionality that appears to solve this issue. See https://developers.facebook.com/docs/messenger-platform/account-linking

    0 讨论(0)
  • 2021-01-30 09:36

    I solved it different way but it works perfectly by graph API,i read mailbox of my page so that when any one can interact by messenger bot than i read pages inbox and iterate through,

    Step 1:

    Do a HTTP get request by graph API , you want a PAGE_UNIQUE_ID from Graph API ,

    GET REQUEST

    https://graph.facebook.com/v2.6/<PAGE_UNIQUE_ID>?fields=conversations.limit(10){participants,updated_time,id}&access_token=<PAGE_ACCESS_TOKEN>
    

    PAGE_UNIQUE_ID Hints:

    Go ===> https://developers.facebook.com/tools/explorer/ ==> Press "Get Token" ===> Select your desired page ===>Finally Submit , You show a id on output that is PAGE_UNIQUE_ID in here.

    Check on browser for resoponse.

    Step 2:

    After doing above http request ,you get a JSON object that will show latest 10 conversation of pages where desired facebook id included.

    Step 3:

    Do iteration through by user full name or you can use lodash or underscore at your choice,

    getUserID(response,'Zahid Rahman')
    
    
    function getUserID(response, fullname) {
      if (response && response.conversations && response.conversations.data) { //Check response is correct
        var conversations = response.conversations.data;                       //Get all conversations
        for (var j = 0; j < conversations.length; j++) {
          var conversationsParticipants = conversations[j].participants.data; 
          for (var k = 0; k < conversationsParticipants.length; k++) {         //Get all particiapnts of a single conversation.
    
            var conversationsParticipantsEach = conversationsParticipants[k];
            if (conversationsParticipantsEach.name === fullname) {             //Check fullname match or not
              console.log("Desired Facebook User ID : " + conversationsParticipants[k].id);
              return conversationsParticipants[k].id;     
            } 
          }
        }
      }
    }
    

    Hope it will help you.

    0 讨论(0)
  • 2021-01-30 09:46

    This is probably what you want: https://developers.facebook.com/docs/apps/for-business

    It allows you to get all of the app-scoped user ids on a per-business basis.

    0 讨论(0)
  • 2021-01-30 09:56

    Unfortunately, there's no way of doing that currently. Asking them to login for new threads is the best way of linking accounts.

    0 讨论(0)
  • 2021-01-30 09:56

    Yes. You can get details like first name, last name, profile pic url, locale, timezone, gender from an api. Only you have to pass is their recipient id/sender id and acccess_token of your messenger bot.

    https://graph.facebook.com/v2.6/USER_ID?fields=first_name,last_name,profile_pic,locale,timezone,gender&access_token=TOKEN
    
    0 讨论(0)
提交回复
热议问题