0

I m using twitter anywhere api for allowing user to sign in with twitter and get their twitter data to store it my table.Since twitter anywhere api is going to expire soon how can i migrate this functionality to oauth.

my javascript:

<script src="https://platform.twitter.com/anywhere.js?id={{twitterappid}}&v=1"></script>
<script type="text/javascript">
var twt_connected = 0;
var Uuid = '2334443224';
$(function(){
if ($('#twtlogin').length) {
  // do something
twttr.anywhere(function(twitter) {
if(twitter.isConnected()){
//alert('Welcome, you are connected');
currentUser = twitter.currentUser;
screenName = currentUser.data('screen_name');
jQuery.ajax({url:"/twitter/Uuid="+Uuid+"/" ,
             type: "POST",
             data: {user: JSON.stringify(currentUser) },
             dataType: "json",
             success: function(result) {
                        }});
document.getElementById("twtlogin").innerHTML = '<img src="/images/icon_tconnected.gif" width="153" height="37" alt="Connected" />';
 }
 });
 }
 });

$("#login").click(function(e){
    e.preventDefault();
    if (twt_connected == 0){
    $.post("/twt-click-time/Uuid="+Uuid+"/","clicked",function(data){})
    twttr.anywhere(function (T) {
             T.bind("authComplete", function (e, user) {
            document.getElementById("twtlogin").innerHTML = '<img src="/images/icon_tconnected.gif" width="153" height="37" alt="Connected" />';
             twt_connected = 1;
             currentUser = T.currentUser;
             screenName = currentUser.data('screen_name');
             jQuery.ajax({url:"/twitter/Uuid="+Uuid+"/" ,
                         type: "POST",
                         data: {user: JSON.stringify(currentUser) },
                         dataType: "json",
                         success: function(result) {
                        }});

             });
             T.signIn();
             });
             }
             });

</script>

I m using django at my backend.

4

1 回答 1

1

我现在正在为烧瓶做这个。最简单的选择就是插入一些服务器端的 oauth 调用。

这是相当多的代码,所以我不会在这里复制和粘贴整个内容,但 simplegeo 的 oauth2 的 github 页面实际上有一个“使用 twitter 登录 django ”演练,应该会有所帮助。

在经历了一些选择之后,我认为我最喜欢twython。这只是做oauth的第一步:

from twython import Twython

t = Twython(app_key='key',
            app_secret='secret',
            callback_url='http://google.com/')
auth_props = t.get_authentication_tokens()
print auth_props
于 2012-12-17T04:41:51.607 回答