【问题标题】:Twitter API 1.1 oauth give me a bad authentification data with PhonegapTwitter API 1.1 oauth 使用 Phonegap 给我一个糟糕的身份验证数据
【发布时间】:2014-05-20 06:21:44
【问题描述】:

使用 Oauth.io 完成 Oauth 身份验证后,我无法访问 user_timeline,它只显示错误的身份验证数据,代码为 215。也许我忘记了一些参数或我的连接错误?我没有发现我的问题有任何问题。我想我错过了一些东西,但我找不到什么。 如果有人可以帮助我,我将我的代码粘贴在下面:)

谢谢

$(document).on( 'deviceready', function() {



 OAuth.initialize("my key");

    $('#twitter-connect').on('click', function() {

    OAuth.popup('twitter', function(error, result) {

    result.get('/1.1/account/verify_credentials.json').done(function(data) {

    console.log(data);

    var screen_name = data.screen_name;

    $.ajax({ 
    url : "https://api.twitter.com/1.1/statuses/user_timeline.json", 
    dataType: "json", 
    type: "get", 
    data:{ 
    screen_name: screen_name 
    },

    error: function(xhr, status){ 
    alert(xhr.responseText); 
    },

    success: function(data, xhr, status){ 
    console.log(data); 
    } 
    }); 
    }); 
    }); 
    });

});

【问题讨论】:

    标签: twitter cordova twitter-oauth


    【解决方案1】:

    您已使用 jQuery.ajax 而不是 OAuth.popup() 的 result 进行 API 调用。看看这个 jsFiddle:http://jsfiddle.net/LCZu3/1/

    你可以这样做:

    $(document).on( 'deviceready', function() {
       OAuth.initialize("my key")
       $('#twitter-connect').on('click', function() {
          OAuth.popup('twitter', function(error, result) {
             result.get('/1.1/account/verify_credentials.json').done(function(data) {
                console.log(data)
    
                var screen_name = data.screen_name
    
                result.get({
                   url: '/1.1/statuses/user_timeline.json',
                   data: {
                      screen_name: screen_name
                   }
                }).done(function(timeline) {
                   console.log(timeline)
                }).error(function(error) {
                   console.log(error)
                })
             })
          })
       })
    })
    

    【讨论】:

      猜你喜欢
      • 2013-01-20
      • 2017-12-30
      • 2013-06-08
      • 2013-06-16
      • 2011-11-16
      • 2013-11-28
      • 2013-04-15
      • 2015-03-13
      • 1970-01-01
      相关资源
      最近更新 更多