Guest User

Untitled

a guest
Jul 16th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import Unsplash from 'unsplash-js';
  3. import './App.css';
  4.  
  5. const unsplash = new Unsplash({
  6. applicationId: '', //removed for security reasons
  7. secret: '',
  8. callbackUrl: 'https://unsplash.com/oauth/',
  9. headers: {
  10. "Accept-Version": "v1",
  11. page: 1
  12. }
  13. });
  14.  
  15. class App extends Component {
  16. constructor(props) {
  17. super(props);
  18.  
  19. this.handleClick = this.handleClick.bind(this);
  20. }
  21.  
  22. componentDidMount() {
  23. const authenticationUrl = unsplash.auth.getAuthenticationUrl(['public']);
  24. console.log(authenticationUrl);
  25. location.assign(authenticationUrl);
  26.  
  27. unsplash.auth.userAuthentication('mountain'.code)
  28. .then(string => JSON.stringify(string))
  29. .then(json => {
  30. unsplash.auth.setVearerToken(json.access_token);
  31. });
  32. }
  33.  
  34. handleClick() {
  35. //let query = document.getElementById('input').value;
  36. fetch('https://api.unsplash.com/photos/?client_id=' + unsplash.applicationId)
  37. .then(response => console.log(response))
  38. .catch(error => console.log('error: ' + error));
  39. }
  40. render() {
  41. return (
  42. <div className="App">
  43. <form id='form'>
  44. <input type='text' id='input' ></input>
  45. <input type='submit' id='submit' onClick={this.handleClick} ></input>
  46. </form>
  47. <div id='field' >
  48. </div>
  49. </div>
  50. );
  51. }
  52. }
  53.  
  54. export default App;
Add Comment
Please, Sign In to add comment