google-photos.mdx 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. ---
  2. slug: /google-photos
  3. ---
  4. import Tabs from '@theme/Tabs';
  5. import TabItem from '@theme/TabItem';
  6. import UppyCdnExample from '/src/components/UppyCdnExample';
  7. # Google Photos
  8. The `@uppy/google-photos` plugin lets users import files from their
  9. [Google Photos](https://photos.google.com) account.
  10. :::tip
  11. [Try out the live example](/examples) or take it for a spin in
  12. [StackBlitz](https://stackblitz.com/edit/vitejs-vite-zaqyaf?file=main.js).
  13. :::
  14. ## When should I use this?
  15. When you want to let users import files from their
  16. [Google Photos](https://photos.google.com) account.
  17. A [Companion](/docs/companion) instance is required for the Google Photos plugin
  18. to work. Companion handles authentication with Google Photos, downloads the
  19. photos/videos, and uploads them to the destination. This saves the user
  20. bandwidth, especially helpful if they are on a mobile connection.
  21. You can self-host Companion or get a hosted version with any
  22. [Transloadit plan](https://transloadit.com/pricing/).
  23. <Tabs>
  24. <TabItem value="npm" label="NPM" default>
  25. ```shell
  26. npm install @uppy/google-photos
  27. ```
  28. </TabItem>
  29. <TabItem value="yarn" label="Yarn">
  30. ```shell
  31. yarn add @uppy/google-photos
  32. ```
  33. </TabItem>
  34. <TabItem value="cdn" label="CDN">
  35. <UppyCdnExample>
  36. {`
  37. import { Uppy, GooglePhotos } from "{{UPPY_JS_URL}}"
  38. const uppy = new Uppy()
  39. uppy.use(GooglePhotos, {
  40. // Options
  41. })
  42. `}
  43. </UppyCdnExample>
  44. </TabItem>
  45. </Tabs>
  46. ## Use
  47. Using Google Photos requires setup in both Uppy and Companion.
  48. ### Use in Uppy
  49. ```js {10-13} showLineNumbers
  50. import Uppy from '@uppy/core';
  51. import Dashboard from '@uppy/dashboard';
  52. import GooglePhotos from '@uppy/google-photos';
  53. import '@uppy/core/dist/style.min.css';
  54. import '@uppy/dashboard/dist/style.min.css';
  55. new Uppy()
  56. .use(Dashboard, { inline: true, target: '#dashboard' })
  57. .use(GooglePhotos, {
  58. target: Dashboard,
  59. companionUrl: 'https://your-companion.com',
  60. });
  61. ```
  62. ### Use with Transloadit
  63. ```js
  64. import { COMPANION_URL, COMPANION_ALLOWED_HOSTS } from '@uppy/transloadit';
  65. import GooglePhotos from '@uppy/google-photos';
  66. uppy.use(GooglePhotos, {
  67. companionUrl: COMPANION_URL,
  68. companionAllowedHosts: COMPANION_ALLOWED_HOSTS,
  69. });
  70. ```
  71. You may also hit rate limits, because the OAuth application is shared between
  72. everyone using Transloadit.
  73. To solve that, you can use your own OAuth keys with Transloadit’s hosted
  74. Companion servers by using Transloadit Template Credentials. [Create a Template
  75. Credential][template-credentials] on the Transloadit site. Select “Companion
  76. OAuth” for the service, and enter the key and secret for the provider you want
  77. to use. Then you can pass the name of the new credentials to that provider:
  78. ```js
  79. import { COMPANION_URL, COMPANION_ALLOWED_HOSTS } from '@uppy/transloadit';
  80. import GooglePhotos from '@uppy/google-photos';
  81. uppy.use(GooglePhotos, {
  82. companionUrl: COMPANION_URL,
  83. companionAllowedHosts: COMPANION_ALLOWED_HOSTS,
  84. companionKeysParams: {
  85. key: 'YOUR_TRANSLOADIT_API_KEY',
  86. credentialsName: 'my_companion_dropbox_creds',
  87. },
  88. });
  89. ```
  90. ### Use in Companion
  91. To sign up for API keys, go to the
  92. [Google Developer Console](https://console.developers.google.com/).
  93. Create a project for your app if you don’t have one yet.
  94. - On the project’s dashboard,
  95. [enable the Google Photos API](https://developers.google.com/photos).
  96. - [Set up OAuth authorization](https://developers.google.com/photos/library/guides/authorization).
  97. The app page has a `"Redirect URIs"` field. Here, add:
  98. ```
  99. https://$YOUR_COMPANION_HOST_NAME/googlephotos/redirect
  100. ```
  101. If you are using Transloadit hosted Companion:
  102. ```
  103. https://api2.transloadit.com/companion/googlephotos/redirect
  104. ```
  105. Google will give you an OAuth client ID and client secret.
  106. Configure the Google key and secret in Companion. With the standalone Companion
  107. server, specify environment variables:
  108. ```shell
  109. export COMPANION_GOOGLE_KEY="Google OAuth client ID"
  110. export COMPANION_GOOGLE_SECRET="Google OAuth client secret"
  111. ```
  112. When using the Companion Node.js API, configure these options:
  113. ```js
  114. companion.app({
  115. providerOptions: {
  116. googlephotos: {
  117. key: 'Google OAuth client ID',
  118. secret: 'Google OAuth client secret',
  119. },
  120. },
  121. });
  122. ```
  123. ## API
  124. ### Options
  125. #### `id`
  126. A unique identifier for this plugin (`string`, default: `'GooglePhotos'`).
  127. #### `title`
  128. Title / name shown in the UI, such as Dashboard tabs (`string`, default:
  129. `'GooglePhotos'`).
  130. #### `target`
  131. DOM element, CSS selector, or plugin to place the drag and drop area into
  132. (`string` or `Element`, default: `null`).
  133. #### `companionUrl`
  134. URL to a [Companion](/docs/companion) instance (`string`, default: `null`).
  135. #### `companionHeaders`
  136. Custom headers that should be sent along to [Companion](/docs/companion) on
  137. every request (`Object`, default: `{}`).
  138. #### `companionAllowedHosts`
  139. The valid and authorised URL(s) from which OAuth responses should be accepted
  140. (`string` or `RegExp` or `Array`, default: `companionUrl`).
  141. This value can be a `string`, a `RegExp` pattern, or an `Array` of both. This is
  142. useful when you have your [Companion](/docs/companion) running on several hosts.
  143. Otherwise, the default value should do fine.
  144. #### `companionCookiesRule`
  145. This option correlates to the
  146. [RequestCredentials value](https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials)
  147. (`string`, default: `'same-origin'`).
  148. This tells the plugin whether to send cookies to [Companion](/docs/companion).
  149. #### `locale`
  150. ```js
  151. export default {
  152. strings: {
  153. pluginNameGooglePhotos: 'GooglePhotos',
  154. },
  155. };
  156. ```
  157. [template-credentials]:
  158. https://transloadit.com/docs/#how-to-create-template-credentials