帐户链接期间的FB bot PSID检索

时间:2016-09-28 17:12:12

标签: node.js facebook facebook-graph-api

嗨我需要一些关于如何在进行帐户关联过程时检索页面范围ID(PSID)或发件人ID的指导。

该文档提出了以下解决方案,但我不知道这如何适合我的POST方法或我的代码中的任何位置,以便我可以将我的唯一公司ID与PSID /发件人ID相关联。

curl -X GET "https://graph.facebook.com/v2.6/me?access_token=PAGE_ACCESS_TOKEN \
      &fields=recipient \
      &account_linking_token=ACCOUNT_LINKING_TOKEN"

Btw上面提到的收件人值是什么?

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

按照以下流程通过帐户关联获取PSID(sender.id)

第1步:通过向您的机器人发送按钮来启动登录过程

function sendAccountLinking(recipientId) {
  var messageData = {
    recipient: {
      id: recipientId
    },
    message: {
      attachment: {
        type: "template",
        payload: {
          template_type: "button",
          text: "Welcome. Link your account.",
          buttons: [{
            type: "account_link",
            url: SERVER_URL + "/authorize"
          }]
        }
      }
    }
  };

  callSendAPI(messageData);
}

第2步::在服务器代码中添加get方法并获取account_linking_token和redirect_uri请求参数。

例如:

/*
 * This path is used for account linking. The account linking call-to-action
 * (sendAccountLinking) is pointed to this URL. 
 * 
 */
app.get('/authorize', function (req, res) {
  console.log('%%%%%%%% AccountLinking Testing');
  var accountLinkingToken = req.query.account_linking_token;
  var redirectURI = req.query.redirect_uri;

  console.log('%%%%%%%% /authorize called with accountLinkingToken %s, redirectURI %s', accountLinkingToken, redirectURI);

  // Authorization Code should be generated per user by the developer. This will 
  // be passed to the Account Linking callback.
  var authCode = "1234567890";

  // Redirect users to this URI on successful login
  var redirectURISuccess = redirectURI + "&authorization_code=" + authCode;

  res.render('authorize', {
    accountLinkingToken: accountLinkingToken,
    redirectURI: redirectURI,
    redirectURISuccess: redirectURISuccess
  });
});

第3步::使用此account_linking_token并进行GET调用以从get方法获取PSIN(sender.id)。

例如httep.get来自你的

https://graph.facebook.com/v2.6/me?access_token=YOUR_PAGE_ACCESS_TOKEN&fields=recipient&account_linking_token=ACCOUNT_LINKING_TOKEN

回应如下:  {“收件人”:“xxxxxxxxxxxx”,“id”:“xxxxxxxxxxxxxx”}

其中receipt是PSID(sender.id),id是appID(pageid)

谢谢, Nagendra Prasad SBR。