Twitter.requestCredential功能响应

Twitter.requestCredential function response

本文关键字:响应 功能 requestCredential Twitter      更新时间:2023-09-26

Twitter.requestCredential函数的预期响应是什么?我在accons.js中配置了我的推特应用程序,如下所示:

ServiceConfiguration.configurations.remove({
service: 'twitter'
});
ServiceConfiguration.configurations.insert({
    service: 'twitter',
    consumerKey: 'XXXXXXXXXXXXXXXXXX',
    secret: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
});

然后我运行这样的函数:

Twitter.requestCredential(function (result) {
    console.log(result);
})

在所有应用程序授权过程成功完成后,我不断获得这些奇怪的字符串"5H7he8sfijie1jccrLnB4oVTdPa-kogKctNpHyQ-18"

我在文档中读到,如果我只需要来自Twitter的OAuth令牌,我可以使用"Twitter"包。https://www.meteor.com/accounts

所以问题是如何从这个函数中获得真正的OAuth令牌?

Twitter.requestCredential可以在GitHub上的Meteor代码库中找到:https://github.com/meteor/meteor/blob/89971d6205dfbe1d8620b88868fb8c65784daaf5/packages/twitter/twitter_client.js

根据该函数的注释,它在完成时调用回调函数credentialRequestCompleteCallbackcredentialRequestCompleteCallback采用一个参数:credentialToken表示成功,Error表示错误。

Twitter.requestCredential发送给credentialRequestCompleteCallbackcredentialToken字符串只是附加到OAuth URL的随机生成的字母数字字符串,以唯一地标识登录请求。

Twitter.requestCredential的实际工作是由OAuth.launchLogin:完成的

  OAuth.launchLogin({
    loginService: "twitter",
    loginStyle: loginStyle,
    loginUrl: loginUrl,
    credentialRequestCompleteCallback: credentialRequestCompleteCallback,
    credentialToken: credentialToken
  });