0

I need to use Twitter's Search API. I read twitter's developer documentation and it says that client side authentication is not recommended anymore. But, since mine is really a small application and on a very tight deadline, I decided to use codebird-js.

Here is my code:

<script type="text/javascript" src="sha1.js"></script>
<script type="text/javascript" src="codebird.js"></script>
<script type="text/javascript">

 function loginTwitter() {
 var cb = new Codebird();
 cb.setConsumerKey("my_consumer_key","my_consumer_secret");
 cb.setToken("my_token", "my_token_secret");
 cb.__call(
  "search_tweets",
  "q=Twitter",
   function (reply) {
   alert("hey");
 },
 true
 );
}

</script>

Dont think there is any problem with the callback of search tweets, since this is what is documented in codebird-js.Kindly suggest any alternatives to make the code work. Also, I enabled the option "Allow application to sign in with twitter" in application settings.

4

1 回答 1

0

您必须对代码进行一些语法更正并调用“loginTwitter()”函数;代码应该是:

<script type="text/javascript" src="sha1.js"></script>
<script type="text/javascript" src="codebird.js"></script>
<script type="text/javascript">

function loginTwitter() {
    var cb = new Codebird();
    cb.setConsumerKey("my_consumer_key", "my_consumer_secret");
    cb.setToken("my_token", "my_token_secret");

    cb.__call(
        "search_tweets",
        "q=Twitter",
        function (reply) {
            alert(JSON.stringify(reply));  //do something with the result
        },
        true
    );
};

loginTwitter();

</script>

并且不要忘记下载用于 javascript 的 codebird 并将其文件放入与您的主文件相同的文件夹中(根据您在脚本中放置的路径)。

于 2013-09-07T21:55:17.280 回答