Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript twitterapi和React_Javascript_Reactjs_Twitter - Fatal编程技术网

Javascript twitterapi和React

Javascript twitterapi和React,javascript,reactjs,twitter,Javascript,Reactjs,Twitter,我现在只是在搞react,我想我会尝试制作一个可以搜索推特的应用程序。我基本上只是按照例子来做,但我无法让它发挥作用。以下是我所拥有的: import React, { Component } from 'react'; import Twitter from 'twitter'; import config from './config.js' class App extends Component { constructor(){ super(); this.Cli

我现在只是在搞react,我想我会尝试制作一个可以搜索推特的应用程序。我基本上只是按照例子来做,但我无法让它发挥作用。以下是我所拥有的:

import React, { Component } from 'react';
import Twitter from 'twitter';
import config from './config.js'



class App extends Component {
  constructor(){
    super();
    this.Client = new Twitter(config);
    this.searchTwitter = this.searchTwitter.bind(this);
  }

  searchTwitter(){
    this.Client.get('search/tweets', {q: 'node.js'}, function(error, tweets, response) {
   console.log(tweets);
 });
   }

  render() {
    return (
      <div className="App">
        <header className="App-header">
          <img src={logo} className="App-logo" alt="logo" />
          <h1 className="App-title">The Test App</h1>
        </header>
        <button style = {{height: "50px", width: "150px"}} onClick = {this.searchTwitter}> CLICK ME </button>
      </div>
    );
  }
}
import React,{Component}来自'React';
从“Twitter”导入Twitter;
从“./config.js”导入配置
类应用程序扩展组件{
构造函数(){
超级();
this.Client=newtwitter(config);
this.searchTwitter=this.searchTwitter.bind(this);
}
searchTwitter(){
this.Client.get('search/tweets',{q:'node.js'},函数(错误,tweets,响应){
console.log(tweets);
});
}
render(){
返回(
测试应用程序
点击我
);
}
}
这只是一个快速测试,你点击按钮,它会搜索推文并将其记录到控制台。问题是我每次都会得到“未定义”,并且我已经检查了密钥和令牌,所以我认为这不是问题所在。
我从未尝试过使用此API,因此非常感谢您的帮助。twitter API似乎不支持CORS请求,因此我们无法通过浏览器对API进行任何调用,因此它对您不起作用。 有关详细信息,请参阅以下链接:
twitter api似乎不支持CORS请求,因此我们无法通过浏览器对api进行任何调用,因此它不适用于您。 有关详细信息,请参阅以下链接:

可能有错误,如果(!error){console.log(tweets);}或者{console.log(error)},您可以这样继续吗
。在这种情况下,如果有错误,它们将被记录到控制台。您确定您的twitter配置正确并且可以正确连接到twitter。如果有错误,您是否可以按此方式进行
if(!error){console.log(tweets);}else{console.log(error)}
。在这种情况下,如果出现错误,它们将被记录到控制台。请确保您的twitter配置正确,并且可以正常连接twitter