0

I am trying to use oauth to make twitter requests from jquery ajax. I have this so far, but I get the javascript error

TypeError: OAuth is not a constructor 

code:

<!DOCTYPE html>
<html>
<head>
<title>test</title>

<script type="text/javascript" src="jquery-2.1.0-beta1.js"></script>
<script type="text/javascript" src="oauth.js"></script>

<script>

    $(function() {

        var oauth = new OAuth(
            "https://api.twitter.com/oauth/request_token",
            "https://api.twitter.com/oauth/access_token",
            "some token",
            "some token",
            '1.0A',
            null,
            'HMAC-SHA1'
        );

        oauth.get(
            "https://api.twitter.com/1.1/trends/place.json?id=23424977",
            "some token", 
            //you can get it at dev.twitter.com for your own apps
            "some token", 
            //you can get it at dev.twitter.com for your own apps
            function (e, data, res) {
                if (e) console.error(e);        
                console.log(require('util').inspect(data));
                done();      
            }
        ); 
    });





</script>

</head>

    <body>




    </body>

</html> 

Does anyone know whats wrong here?

Here is the source for oauth.js http://oauth.googlecode.com/svn/code/javascript/oauth.js

Thanks.

4

2 回答 2

0

看起来您在不需要新关键字时正在使用它。据我所知,在包含该库之后,您就可以在全球范围内使用 oauth 对象。所以不需要在你的代码中重新定义 oauth。检查在 chrome 控制台中键入“oauth”,它应该是自动完成的,如果按 enter,你会看到整个对象。

另一方面,oauth 似乎没有 get 方法。

但如果它有它,你应该像这样使用它:oauth.get(params)

很抱歉没有提供更多帮助,但我不知道该库,指出它只是 js 概念。

问候,

吉列尔莫

于 2013-09-20T22:23:08.330 回答
0

如果您在 PHP 服务器上托管您的网站,我建议您使用此方法使用 Twitter API 版本 1.1 检索 user_timeline 的最简单 PHP 示例

如果你不能使用 PHP 方法,请查看这篇文章,因为它解释了如何制作你的 Twitter 应用程序,你需要获取你的 oauth_access 令牌和 oauth_access_token_secrete 以及你的 consumer_key 和 consumer_secrete。

希望这可以帮助。

于 2013-09-20T22:31:52.223 回答