38

Npm module that returns user's social network avatar without need of tok...

 5 years ago
source link: https://www.tuicool.com/articles/hit/yQ7rqu2
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

network-avatar-picker

A npm module that returns a user's avatar from his social networks as Buffer or as URL. You can choose among Facebook, Twitter, Instagram, Tumblr, Vimeo, Github and Youtube provider. Then, you just need to pass a username without the need of token or API keys and retrieve user's social network profile picture!

Supported Providers

  • Facebook
  • Github
  • Instagram
  • Tumblr
  • Twitter
  • Vimeo
  • Youtube

Usage

First, install network-avatar-picker as a dependency:

npm install --save network-avatar-picker

Then you should require in order to be able use it:

const AvatarPickerService = require('network-avatar-picker');
const avatarPicker = new AvatarPickerService();

Use the async methods of the avatarPicker instance to get user avatars:

Get avatar as Buffer:

avatarPicker.twitter.getAvatar(username)
avatarPicker.instagram.getAvatar(username)
avatarPicker.tumblr.getAvatar(username)
avatarPicker.vimeo.getAvatar(username)
avatarPicker.facebook.getAvatar(username)
avatarPicker.github.getAvatar(username)
avatarPicker.youtube.getAvatar(username)

Get avatar as URL:

avatarPicker.twitter.getAvatarUrl(username)
avatarPicker.instagram.getAvatarUrl(username)
avatarPicker.tumblr.getAvatarUrl(username)
avatarPicker.vimeo.getAvatarUrl(username)
avatarPicker.facebook.getAvatarUrl(username)
avatarPicker.github.getAvatarUrl(username)
avatarPicker.youtube.getAvatarUrl(username)

Example

  1. Fetch twitter's cnn user profile picture:

Buffer:

(async () => {
    try {
      const res = await avatarPicker.twitter.getAvatar('cnn');
    } catch (e) {
      // Deal with the fact the chain failed
    }
})();

URL:

(async () => {
    try {
      const res = await avatarPicker.twitter.getAvatarUrl('cnn');
    } catch (e) {
      // Deal with the fact the chain failed
    }
})();
  1. Fetch facebook's zuck user profile picture:

Buffer:

(async () => {
    try {
      const res = await avatarPicker.facebook.getAvatar('zuck');
    } catch (e) {
      // Deal with the fact the chain failed
    }
})();

URL:

(async () => {
    try {
      const res = await avatarPicker.facebook.getAvatarUrl('zuck');
    } catch (e) {
      // Deal with the fact the chain failed
    }
})();
  1. Fetch instagram's cnn user profile picture:

Buffer:

(async () => {
    try {
      const res = await avatarPicker.instagram.getAvatar('cnn');
    } catch (e) {
      // Deal with the fact the chain failed
    }
})();

URL:

(async () => {
    try {
      const res = await avatarPicker.instagram.getAvatarUrl('cnn');
    } catch (e) {
      // Deal with the fact the chain failed
    }
})();

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK