2016-08-31 6 views
0

の情報私は、ユーザーが保存しているとしてMeteor.loginWithFacebookもらいましょう。Facebook ID流星

を使用しています:私はとき

{ 
    "_id" : "cnzMXwmvtF42Dfy4q", 
    "createdAt" : ISODate("2016-08-31T15:58:00.814Z"), 
    "services" : { 
     "facebook" : { 
      "accessToken" : "randomtoken", 
      "expiresAt" : 1477842969226, 
      "id" : "randomid", 
      "email" : "[email protected]", 
      "name" : "Name", 
      "first_name" : "Firstname", 
      "last_name" : "Lastname", 
      "link" : "https://www.facebook.com/...", 
      "gender" : "male", 
      "locale" : "en_US", 
      "age_range" : { 
       "min" : 21 
      } 
     }, 
     "resume" : { 
      "loginTokens" : [ 
       { 
        "when" : ISODate("2016-08-31T15:58:00.818Z"), 
        "hashedToken" : "randomtoken" 
       } 
      ] 
     } 
    }, 
    "profile" : { 
     "name" : "Firstname" 
    } 
} 

しかし: console.log(Meteor.user().services);

それはとしてundefinedを返します。

私がconsole.log(Meteor.user().profile);を実行すると、nameが正しく表示されます。私は流星にFacebookの情報を取得するにはどうすればよい

質問

答えて

1

デフォルトでは、ユーザー名、電子メール、およびプロファイルオブジェクトのみがクライアントに公開されます。必要なフィールドを公開するには、パブリケーションを作成し、それをクライアントに登録する必要があります。

これは、services.facebookオブジェクトを直接公開する目的に合わないことがあります。 Googleやユーザー名/パスワードなどの複数の認証方法を使用している場合は、必要な情報をさまざまなフィールドにコピーしてユーザー文書を標準化することをお勧めします。

Accounts.onCreateUser(function(options, user) { 
    // Copy first name and last name from user services 
    if (user.services.google) { 
     user.firstName = user.services.google.given_name; 
     user.lastName = user.services.google.family_name; 
    } else if (user.services.facebook) { 
     user.firstName = user.services.facebook.first_name; 
     user.lastName = user.services.facebook.last_name; 
    } 

    // You can use the profile object to pass in user information in a password signup form 
    if (options && options.profile) { 
     if (options.profile.firstName) { 
      user.firstName = options.profile.firstName; 
     } 

     if (options.profile.lastName) { 
      user.lastName = options.profile.lastName; 
     } 
    } 

    return user; 
}); 

Note that it is NOT recommended that you use the profile object to store user data.

+0

彼らは通常行く名前や電子メールを追加する方法があります:私はFacebookの、グーグル、そして定期的に古い電子メール/パスワードを使用するプロジェクトを処理する方法ここで

です電子メールとパスワードで登録しますか? 'Meteor.user()。emails [0]'に行く電子メールと 'Meteor.user()。profile'のメール?私は 'user.profile.name = user.services.facebook.first_name;'を使用しようとしましたが、 '未定義のプロパティ 'name'を設定できません。 –

+0

nvm、それ以前に' user.profile = {} 'を作成しました –

関連する問題