Browse Source

username field is deprecated in FB APi v > 2.00

Andrey Sergienko 10 years ago
parent
commit
b9c4c3b8cb
2 changed files with 5 additions and 5 deletions
  1. 3 3
      priv/facebook_sdk.dtl
  2. 2 2
      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,first_name,last_name,email,birthday", 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,first_name,last_name,email,birthday", 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,first_name,last_name,email,birthday", function(response){fbLogin(response);});
       }, {scope: 'email,user_birthday'});
       }, {scope: 'email,user_birthday'});
   });
   });
 }
 }

+ 2 - 2
src/facebook.erl

@@ -15,7 +15,6 @@ api_event(fbLogin, Args, _Term)-> JSArgs = n2o_json:decode(Args), avz:login(face
 
 
 registration_data(Props, facebook, Ori)->
 registration_data(Props, facebook, Ori)->
     Id = proplists:get_value(<<"id">>, Props),
     Id = proplists:get_value(<<"id">>, Props),
-    UserName = binary_to_list(proplists:get_value(<<"username">>, Props)),
     BirthDay = case proplists:get_value(<<"birthday">>, Props) of
     BirthDay = case proplists:get_value(<<"birthday">>, Props) of
         undefined -> {1, 1, 1970};
         undefined -> {1, 1, 1970};
         BD -> list_to_tuple([list_to_integer(X) || X <- string:tokens(binary_to_list(BD), "/")]) end,
         BD -> list_to_tuple([list_to_integer(X) || X <- string:tokens(binary_to_list(BD), "/")]) end,
@@ -23,9 +22,10 @@ registration_data(Props, facebook, Ori)->
     error_logger:info_msg("Props: ~p",[Props]),
     error_logger:info_msg("Props: ~p",[Props]),
     Id = proplists:get_value(<<"id">>, Props),
     Id = proplists:get_value(<<"id">>, Props),
     Email = email_prop(Props, facebook),
     Email = email_prop(Props, facebook),
+    [UserName|_] = string:tokens(binary_to_list(Email),"@"), Cover = case proplists:get_value(<<"cover">>,Props) of undefined -> ""; P -> case proplists:get_value(<<"source">>,P#struct.lst) of undefined -> ""; C -> binary_to_list(C) end end,
     Ori#user{   id = Email,
     Ori#user{   id = Email,
                 display_name = UserName,
                 display_name = UserName,
-                avatar = "https://graph.facebook.com/" ++ UserName ++ "/picture",
+                images = [{fb_avatar,"https://graph.facebook.com/" ++ binary_to_list(Id) ++ "/picture"},{fb_cover,Cover}|Ori#user.images],
                 email = Email,
                 email = Email,
                 names = proplists:get_value(<<"first_name">>, Props),
                 names = proplists:get_value(<<"first_name">>, Props),
                 surnames = proplists:get_value(<<"last_name">>, Props),
                 surnames = proplists:get_value(<<"last_name">>, Props),