2013-05-06 90 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}}

相關問題