2013-05-06 16 views
0

我在做一个使用Meteor的项目。人们可以使用Twitter登录。我想知道是否有一种方法可以在Accounts.onCreateUser中从Twitter获取某人的个人资料图片。这里是我在我的:你如何得到某人在流星上的Twitter个人资料照片?

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; 
}); 

谢谢!在

回答

0

按照该API(https://dev.twitter.com/docs/api/1/get/users/profile_image/%3Ascreen_name)补充一点:

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):

你需要得到GET users/show和解析user对象profile_image_url

+0

感谢兄弟,这工作。 – moni 2013-05-12 21:49:32

+1

api 1.0已弃用且不再可用。 – pahan 2013-09-23 05:55:18

+0

我还提到过如何使用1.1,你需要从用户对象中获取'/ users/show'并从'profile_image_url'中取出。您需要首先使用OAuth并使用该令牌发出请求 – Akshat 2013-09-23 06:59:05

0

当用户使用Twitter URL为个人资料登录时图片在Users集合中设置为services.twitter.profile_image_url andservices.twitter.profile_image_url_https所以你可以读出这些URL。

我使用下面的行设置一个用户在配置文件中的对象,默认情况下是在客户端可见Twitter个人资料PIC:

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

与Twitter的API 1.0弃用。接受的答案不再有效。

Meteor.user().services.twitter.profile_image_url 

为我工作。

1

我已将流星包accounts-uiaccounts-twitter添加到我的应用。 http://docs.meteor.com/#accountsui 这些软件包真的很容易添加Twitter OAuth登录功能。

更好:我可以从任何地方通过Meteor.user()访问当前用户。 甚至更​​好,他们来了他们自己的模板。所以我可以在我的应用程序的任何地方使用 {{services.twitter.screenName}}来获取用户twitter处理。 {{services.twitter.profile_image_url}}为头像图片网址。并且用于Twitter用户名的 {{profile.name}}

相关问题