我正在尝试使用 codebird.js 通过 javascript 登录 Twitter
我不知道如何在登录后获取用户的用户 ID、名称和其他信息,并控制 session 是否处于事件状态。 我从这段代码开始:
<script type="text/javascript">
var cb = new Codebird;
cb.setConsumerKey("uGpF9dGap2nvIplIz0sIor2UH", "M9lEpsOyrEiyz0tjJ2uERWGZIWEEg681KdJBTzk3UhRnUpTCgf");
//cb.setToken("403332774-Fn288SA96MuJnd6OzMyRWtjLyoZ509TLiLwTv6pl", "XyMg5eHaf5ahQHKle72EPruXgJx4ifUq2VAmG1j5xCbnD");
$('#login').click(function(){
cb.__call(
"oauth_requestToken",
{oauth_callback: "oob"},
function (reply) {
// stores it
cb.setToken(reply.oauth_token, reply.oauth_token_secret);
// gets the authorize screen URL
cb.__call(
"oauth_authorize",
{},
function (auth_url) {
window.open(auth_url,"MsgWindow",'height=202,width=800');
}
);
}
);
});
</script>
html:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1 id="login">login twitter</h1>
<script type="text/javascript" src="../js/libs/jquery.min.js"> </script>
<script src="../js/libs/codebird.js"></script>
</body>
</html>
oauth_authorize 回调可以返回一个响应,我可以在其中获取用户信息?
最佳答案
您需要创建一个 pin 页面,在其中输入您在 auth_authorize 之后获得的 pin。screen_name 和其他凭据是您从服务器获得的响应的一部分,以表明您已获得完全授权。
P.S:不要将您生成的 token 设置为用于身份验证/授权的 token ,除非您希望人们代表创建 Twitter 应用程序的帐户发布推文。
关于javascript - 使用 codebird.js 使 twitter 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28352530/