你如何在 Meteor 上获取某人的 Twitter 个人资料图片? [英] How do you get someones Twitter profile picture on Meteor?
问题描述
我正在使用 Meteor 做一个项目.人们可以使用 Twitter 登录.我想知道是否有办法在 Accounts.onCreateUser 中从 Twitter 获取某人的个人资料图片.这是我的:
I'm doing a project using Meteor. People can log in with Twitter. I was wondering if there was a way to get someones profile picture from Twitter in the 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;
});
谢谢!
推荐答案
根据 API (https://dev.twitter.com/docs/api/1/get/users/profile_image/%3Ascreen_name) 将其添加到:
As per the API (https://dev.twitter.com/docs/api/1/get/users/profile_image/%3Ascreen_name) add this in:
options.profile.display_picture="http://api.twitter.com/1/users/profile_image/"+twitterInfo.screenName;
这是传统方式,在 api 1.1 中稍微困难一些 (https://dev.twitter.com/docs/user-profile-images-and-banners):
This was the traditional way, in api 1.1 its slightly harder (https://dev.twitter.com/docs/user-profile-images-and-banners):
您需要获取 GET users/show
并解析 profile_image_url
You need to get GET users/show
and parse the user
object for profile_image_url
这篇关于你如何在 Meteor 上获取某人的 Twitter 个人资料图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!