How do you get a Twitter profile picture on Meteor?

I am doing a project using Meteor. People can log in using Twitter. I was wondering if there is a way to get the profile picture from Twitter in Accounts.onCreateUser. Here's what I have in mine:

Accounts.onCreateUser(function(options, user) { var twitterInfo = user.services.twitter; if (options.profile){ options.profile.createdAt = new Date();//now! options.profile.twitterId = twitterInfo.id; options.profile.username = twitterInfo.screenName; options.profile.name = options.profile.name; user.profile = options.profile; } return user; }); 

Thanks!

0
source share
4 answers

According to the API ( https://dev.twitter.com/docs/api/1/get/users/profile_image/%3Ascreen_name ) add this to:

 options.profile.display_picture="http://api.twitter.com/1/users/profile_image/"+twitterInfo.screenName; 

This was the traditional way, in api 1.1 it is a bit more complicated ( https://dev.twitter.com/docs/user-profile-images-and-banners ):

You need to get GET users/show and profile_image_url user object for profile_image_url

0
source

with disabling twitter api 1.0. the accepted answer is no longer valid.

 Meteor.user().services.twitter.profile_image_url 

worked for me.

+6
source

I added Meteor packages - ui and accounts-twitter to the application. http://docs.meteor.com/#accountsui These packages easily add Twitter OAuth login capabilities.

Even better: I can access the current user through Meteor.user() from anywhere. And even better, they come, they have their own templates. Therefore, I can simply use {{services.twitter.screenName}} anywhere in my application to get custom twitter. {{services.twitter.profile_image_url}} for the avatar image URL. And also {{profile.name}} for the Twitter username.

+1
source

When a user logs in with a Twitter URL for the pic profile, it is set in the Users collection in services.twitter.profile_image_url and services.twitter.profile_image_url_https , so you can just read these URLs.

I use the following line to set the twitter user profile profile in the profile object, which is displayed to the client by default:

 Meteor.users.update({_id:Meteor.userId()}, {$set {"profile.twitterpic":user.services.twitter.profile_image_url}}); 
0
source

Source: https://habr.com/ru/post/953911/


All Articles