修改user.profile使用Accounts.onCreateUser为loginWithMeetup [英] Modifying user.profile using Accounts.onCreateUser for loginWithMeetup

查看:226
本文介绍了修改user.profile使用Accounts.onCreateUser为loginWithMeetup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户使用的聚会包登录创建一个帐户,我希望得到一些更多的值,如用户的全名和URL,以他们的个人资料图片,然后将它们存储在user.profile。目前,我检查,如果该服务是聚会,执行以下GET请求,并试图将其存储在user.profile。

When a user creates an account using the the Meetup login package, I want to get a few more values such as the user's full name and URL to their profile picture then store them in user.profile. Currently, I'm checking if the service is "meetup", performing the following GET request and trying to store it in user.profile.

if (service == "meetup") {
        var accessToken = user.services.meetup.accessToken;

        var request = Meteor.http.get('https://api.meetup.com/2/profiles',{
            params : {
                access_token : accessToken
            },
            headers: {"User-Agent": "Meteor/1.0"}
        });

        if(result.error){
            throw result.error;
        }

        profile = _.pick(request.results,
            'name',
            'photo_url'
        );

        user.profile = profile;

        return user;

    }

不过,我得到一个错误,当我尝试创建一个帐户。请注意,我能够创建一个帐户,如果我要删除在的code。如果(服务==聚会)尽管没有领域,我需要让我知道问题出在这里。我怎样才能获得用户的全名和个人资料图片URL,并将其存储在user.profile?

However, I'm getting an error when I try to create an account. Note that I am able to create an account if I were to remove the code under if (service == "meetup") albeit without the fields I need so I know the problem is in here. How can I obtain the user's full name and profile picture URL and store them under user.profile?

提前感谢:)

推荐答案

OP这里。感谢您对其他的答案!我还是设法得到code工作。我尝试了一些不同的东西,所以我没有什么隔离是造成问题,但我是可以肯定的部分都,我用,而不是HTTP.get Meteor.http.get(如@sbking和@fuzzybabybunny建议)和我是用/型材/中/ 2,而不是在请求/ 2 /部件(谢谢@mlc)。

OP here. Thank you for the other answers! I did manage to get the code to work. I tried a few different things so I didn't isolate what was causing the problem but I'm sure parts of it were that I was using Meteor.http.get instead of HTTP.get (as @sbking and @fuzzybabybunny suggested) and that I was using /2/profile/ instead of /2/member in the request (Thank you @mlc).

在最后,我决定使用一个API密钥由我创建像以前那样一个访问令牌,而不是一个空的聚会帐户。

In the end, I decided to use an API key from an empty Meetup account I created instead of an access token like before.

下面是code:

if (service == "meetup") {
        var meetupId = user.services.meetup.id;
        var target = 'https://api.meetup.com/2/member/' + meetupId + '?key=' + MEETUP_API_KEY + '&signed=true';

        var result = HTTP.get(target, {
            params: {
                format: 'json'
            }
        });

        var userProperties = result.data;

        options.profile = {
            'name': userProperties.name,
            'link': userProperties.link,
            'bio': userProperties.bio,
            'picture': userProperties.photo.photo_link,
            'id': meetupId
        };

        user.profile = options.profile;

        return user;

    }

以上code不存放,它将在其最终形式之前验证返回的数据。

The above code doesn't validate the returned data before storing it, which it will in its final form.

我希望这有助于有类似问题的人。

I hope this helps anyone with a similar question.

这篇关于修改user.profile使用Accounts.onCreateUser为loginWithMeetup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆