gpt4 book ai didi

javascript - 在meteor oauth中访问github用户数据

转载 作者:行者123 更新时间:2023-12-03 10:41:18 24 4
gpt4 key购买 nike

我正在尝试使用 github 对用户进行身份验证,然后将其 avatar_url 传递给客户端。简化的结构如下所示。

server/
publications.js
client/
users/
login.js
main.js

在我的 client/users/login.js 文件中,我尝试获取包含头像网址的用户对象的权限

Accounts.ui.config({
requestPermissions: {
github: ['user']
}
});

然后在我的 server/publications.js 中,我尝试发布 the data related to the avatar url .

Meteor.publish('userData', function() {
if(this.userId) {
return Meteor.users.find(
{ _id: this.userId }, {
fields: {
'services.github.id': 1,
'services.github.user.avatar_url': 1
}
})
} else {
this.ready();
}
});

但是,当我获取用户对象时,我从未获取与 github 用户相关的数据。如何使用 OAuth 访问用户?

最佳答案

请看一下这个示例代码,您是否捕获了 CreateUser 上的 Github 配置文件数据?

编辑:这是服务器端代码,例如服务器/accounts.js

Accounts.onCreateUser(function (options, user) {
var accessToken = user.services.github.accessToken,
result,
profile;
result = Meteor.http.get("https://api.github.com/user", {
params: {
access_token: accessToken
}
});
if (result.error)
throw result.error;

profile = _.pick(result.data,
"login",
"name",
"avatar_url",
"url",
"company",
"blog",
"location",
"email",
"bio",
"html_url");

user.profile = profile;

return user;
});

Code found here

关于javascript - 在meteor oauth中访问github用户数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28769795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com