Browse Source

Get user cover image URL during login/registration

Andrey Sergienko 10 years ago
parent
commit
2a7442c3f4
2 changed files with 5 additions and 4 deletions
  1. 3 3
      priv/facebook_sdk.dtl
  2. 2 1
      src/facebook.erl

+ 3 - 3
priv/facebook_sdk.dtl

@@ -7,7 +7,7 @@ window.fbAsyncInit = function() {
       var inIframe= top!=self;
       var inIframe= top!=self;
   //    setFbIframe(inIframe);
   //    setFbIframe(inIframe);
       if(inIframe && response.status == 'connected' && fbLogin)
       if(inIframe && response.status == 'connected' && fbLogin)
-        FB.api("/me?fields=id,username,first_name,last_name,email,birthday", function(response){ fbLogin(response);});
+        FB.api("/me?fields=id,username,first_name,last_name,email,birthday,cover", function(response){ fbLogin(response);});
   //  }
   //  }
   });
   });
 };
 };
@@ -15,9 +15,9 @@ window.fbAsyncInit = function() {
 function fb_login(){
 function fb_login(){
   FB.getLoginStatus(function(response){
   FB.getLoginStatus(function(response){
     if(response.status == 'connected'){
     if(response.status == 'connected'){
-      if(fbLogin) FB.api("/me?fields=id,username,first_name,last_name,email,birthday", function(response){fbLogin(response);});
+      if(fbLogin) FB.api("/me?fields=id,username,first_name,last_name,email,birthday,cover", function(response){fbLogin(response);});
     } else FB.login(function(r){
     } else FB.login(function(r){
-        if(r.authResponse && fbLogin) FB.api("/me?fields=id,username,first_name,last_name,email,birthday", function(response){fbLogin(response);});
+        if(r.authResponse && fbLogin) FB.api("/me?fields=id,username,first_name,last_name,email,birthday,cover", function(response){fbLogin(response);});
       }, {scope: 'email,user_birthday'});
       }, {scope: 'email,user_birthday'});
   });
   });
 }
 }

+ 2 - 1
src/facebook.erl

@@ -32,7 +32,8 @@ registration_data(Props, facebook, Ori)->
                 tokens = [{facebook,Id}|Ori#user.tokens],
                 tokens = [{facebook,Id}|Ori#user.tokens],
                 birth = {element(3, BirthDay), element(1, BirthDay), element(2, BirthDay)},
                 birth = {element(3, BirthDay), element(1, BirthDay), element(2, BirthDay)},
                 register_date = erlang:now(),
                 register_date = erlang:now(),
-                status = ok }.
+                status = ok,
+                cover = proplists:get_value(<<"source">>, (proplists:get_value(<<"cover">>, Props))#struct.lst) }.
 
 
 email_prop(Props, _) -> proplists:get_value(<<"email">>, Props).
 email_prop(Props, _) -> proplists:get_value(<<"email">>, Props).