sdoomz / react-google-picker

Google Picker for React
MIT License
45 stars 46 forks source link
google-picker react

React google picker

Simple react wrapper for Google Picker API

Installation

npm install react-google-picker

Usage

<GooglePicker clientId={'your-client-id'}
              developerKey={'your-developer-key'}
              scope={['https://www.googleapis.com/auth/drive.readonly']}
              onChange={data => console.log('on change:', data)}
              onAuthFailed={data => console.log('on auth failed:', data)}
              multiselect={true}
              navHidden={true}
              authImmediate={false}
              mimeTypes={['image/png', 'image/jpeg', 'image/jpg']}
              query={'a query string like .txt or fileName'}
              viewId={'DOCS'}>
   <MyCustomButton />
</GooglePicker>

Authentication token

You might want to get the Oauth token in order to use it later, for example in order to download the selected file. You can do so by using onAuthenticate:

<GooglePicker clientId={'your-client-id'}
              developerKey={'your-developer-key'}
              scope={['https://www.googleapis.com/auth/drive.readonly']}
              onChange={data => console.log('on change:', data)}
              onAuthenticate={token => console.log('oauth token:', token)}
              onAuthFailed={data => console.log('on auth failed:', data)}
              multiselect={true}
              navHidden={true}
              authImmediate={false}
              mimeTypes={['image/png', 'image/jpeg', 'image/jpg']}
              viewId={'DOCS'}>
   <MyCustomButton />
</GooglePicker>

Custom build method

You can override the default build function by passing your custom function which receives two arguments:

Demo

npm install
npm start
open http://localhost:8080

Don't forget to add new origins at console.developers.google.com

Feel free to feel free