Skip to content

Commit

Permalink
[google] add support for Google Avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
JorgenEvens committed Dec 27, 2019
1 parent 9306f37 commit 95d9f5a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ The app is configured using environment variables which you either add to your `
| NETWORKS | The social networks available to this deployment, if no value is set all are enabled. | `undefined` |
| VKONTAKTE\_KEY | A [Vkontakte service key](https://vk.com/dev/access_token?f=3.%20Service%20Token) to perform API requests with. | `undefined` |
| VKONTAKTE\_API_VERSION | The API version to use for Vkontakte | `"5.101"` |
| GOOGLE\_API_KEY | The [API Key](https://console.cloud.google.com/apis/credentials) to a Google Cloud Platform project that has access to the People API. | `undefined` |

## Contributing

Expand Down
Binary file modified app.hosted.yaml
Binary file not shown.
4 changes: 3 additions & 1 deletion src/lib/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ module.exports = {
LIMIT_REFERER: load_env('LIMIT_REFERER', null),

VKONTAKTE_KEY: load_env('VKONTAKTE_KEY', null),
VKONTAKTE_API_VERSION: load_env('VKONTAKTE_API_VERSION', '5.101')
VKONTAKTE_API_VERSION: load_env('VKONTAKTE_API_VERSION', '5.101'),

GOOGLE_API_KEY: load_env('GOOGLE_API_KEY', null)
};
20 changes: 13 additions & 7 deletions src/networks/google/strategies.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
const fetch = require('lib/fetch');
const _get = require('lodash/get');
const { GOOGLE_API_KEY } = require('lib/env');

async function picasaweb(username) {
username = encodeURIComponent(username);

const res = await fetch(`https://picasaweb.google.com/data/entry/api/user/${username}?alt=json`);
const key = encodeURIComponent(GOOGLE_API_KEY || '');

if (!res.ok)
async function peopleApi(username, { req }) {
if (!GOOGLE_API_KEY)
return null;

const { size = 100 } = req.query || {};

username = encodeURIComponent(username);

const res = await fetch(`https://people.googleapis.com/v1/people/${username}?personFields=photos&key=${key}`);
const body = await res.json();

return _get(body, 'entry.gphoto$thumbnail.$t');
const url = _get(body, 'photos.0.url');

return url.replace(/=s\d+/, `=s${size}`);
}

module.exports = [
picasaweb
peopleApi
];

0 comments on commit 95d9f5a

Please sign in to comment.