嗨,我需要一些有关如何在进行帐户链接过程时检索页面范围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"


顺便说一句,上面的收件人值是指什么?

感谢您的帮助!

最佳答案

请按照以下过程通过帐户链接获取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”}

其中接收者是PSID(sender.id),id是appID(pageid)

谢谢,
Nagendra Prasad SBR。

10-02 13:23