尝试使用reactjs提取instagram API时出现Promise错误

时间:2018-11-21 07:29:05

标签: reactjs react-redux instagram instagram-api

  

无法加载资源:服务器响应状态为400()   index.js:65在handleErrors处未捕获(承诺)错误(index.js:65)   home:1无法加载https://api.instagram.com/oauth/authorize/?client_id=28cd69add25e4204acc8d8ed392d7683&redirect_uri=http://localhost:3000/home&response_type=json&scope=public_content:飞行前响应无效(重定向)

import React, { Component } from 'react';
import SearchBar from './search_bar';
//import ProfileList from './profilelist'
//import { user} from 'fetch-instagram';
import ig from 'fetch-instagram';

const instagram = ig({
  accessToken: '***********************',
  resirectUri:"http://localhost:3000/home",
});
const users = instagram.user();

users.then(res => console.log(res));

class InstaApp extends Component {
  constructor(props){
    super(props);

    this.state = { 
        profiles: []
    };

}
componentDidMount(){
  this.profileSearch();
}

profileSearch(searchTerm) {
  fetch("https://api.instagram.com/oauth/authorize/?client_id=acess_token&redirect_uri=http://localhost:3000/home&response_type=json&scope=public_content", {
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
      }
    })
    .then(response => {
      return response.json();
    }).then(result => {
      console.log(result);
      this.setState({
        user: result.user,

      });
    });
}


  render() {

    return (
      <div>
        <SearchBar onSearchTermChange={searchTerm => this.profileSearch(searchTerm)}/>
        {/* <ProfileList 
          onProfileSelect={userSelected => this.setState({selectedProfile: userSelected})}
          profile={this.state.profiles} /> */}
      </div>
    );
  }
}

export default InstaApp;

home:1未捕获(承诺)TypeError:无法获取

0 个答案:

没有答案