Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[google] add support for Google Avatar #12

Merged
merged 1 commit into from
Dec 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ The app is configured using environment variables which you either add to your `
| **Network Configuration** | | |
| 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"` |
| 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: 16 additions & 4 deletions src/networks/google/strategies.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
const fetch = require('lib/fetch');
const _get = require('lodash/get');
const { GOOGLE_API_KEY } = require('lib/env');

const key = encodeURIComponent(GOOGLE_API_KEY || '');

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

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

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

const res = await fetch(`https://picasaweb.google.com/data/entry/api/user/${username}?alt=json`);
const res = await fetch(`https://people.googleapis.com/v1/people/${username}?personFields=photos&key=${key}`);

if (!res.ok)
return null;

const body = await res.json();
const url = _get(body, 'photos.0.url');

if (!url)
return null;

return _get(body, 'entry.gphoto$thumbnail.$t');
return url.replace(/=s\d+/, `=s${size}`);
}

module.exports = [
picasaweb
peopleApi
];